test_sfinae.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Boost.TypeErasure library
  2. //
  3. // Copyright 2011 Steven Watanabe
  4. //
  5. // Distributed under the Boost Software License Version 1.0. (See
  6. // accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // $Id$
  10. #include <boost/type_erasure/any.hpp>
  11. #include <boost/type_erasure/builtin.hpp>
  12. #include <boost/type_traits/is_constructible.hpp>
  13. #include <boost/type_traits/is_copy_constructible.hpp>
  14. #include <boost/mpl/vector.hpp>
  15. #include <boost/mpl/assert.hpp>
  16. using namespace boost::type_erasure;
  17. #if defined(BOOST_TYPE_ERASURE_SFINAE_FRIENDLY_CONSTRUCTORS)
  18. using boost::is_copy_constructible;
  19. template<class T>
  20. using is_move_constructible = boost::is_constructible<T, T&&>;
  21. template<class T>
  22. using is_mutable_constructible = boost::is_constructible<T, T&>;
  23. using move_constructible = boost::mpl::vector<constructible<_self(_self&&)>, destructible<> >;
  24. using mutable_copy = boost::mpl::vector<constructible<_self(_self&)>, destructible<> >;
  25. BOOST_MPL_ASSERT_NOT((is_copy_constructible<any<destructible<> > >));
  26. BOOST_MPL_ASSERT((is_copy_constructible<any<copy_constructible<> > >));
  27. BOOST_MPL_ASSERT_NOT((is_copy_constructible<any<move_constructible> >));
  28. // only is_copy_constructible seems to work on msvc and
  29. // even that breaks when we add a non-const copy constructor.
  30. #if !BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1912)) && \
  31. !BOOST_WORKAROUND(BOOST_GCC, < 70000) && \
  32. !BOOST_WORKAROUND(__clang__major__, < 4)
  33. BOOST_MPL_ASSERT_NOT((is_mutable_constructible<any<destructible<> > >));
  34. BOOST_MPL_ASSERT_NOT((is_move_constructible<any<destructible<> > >));
  35. BOOST_MPL_ASSERT((is_mutable_constructible<any<copy_constructible<> > >));
  36. BOOST_MPL_ASSERT((is_move_constructible<any<copy_constructible<> > >));
  37. BOOST_MPL_ASSERT_NOT((is_mutable_constructible<any<move_constructible> >));
  38. BOOST_MPL_ASSERT((is_move_constructible<any<move_constructible> >));
  39. BOOST_MPL_ASSERT((is_mutable_constructible<any<mutable_copy> >));
  40. BOOST_MPL_ASSERT_NOT((is_copy_constructible<any<mutable_copy> >));
  41. BOOST_MPL_ASSERT_NOT((is_move_constructible<any<mutable_copy> >));
  42. #endif
  43. #endif