Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <utility>
- // main.cpp
- #include <type_traits>
- #include <cstdlib>
- #include <cassert>
- namespace
- {
- template< typename type >
- constexpr std::decay_t< type > any = std::decay_t< type >{};
- static_assert(!any< volatile bool const & >); // is definitely constexpr
- // try to construct from or bind (for references) to ...
- #if 1
- // ... variable template
- template< typename type, type cvrefvalue = std::forward< type >(any< type >) >
- // even for value:
- // main.cpp:20:44: error: non-type template argument is not a constant expression
- // template< typename type, type cvrefvalue = any< type > >
- // ^
- #elif 0
- // ... free constexpr variable
- constexpr bool b = false;
- template< typename type, type cvrefvalue = b >
- // ok for (cv-ref-qualified) values, but for (cv-qualified) references:
- // main.cpp:27:44: error: value of type 'const bool' is not implicitly convertible to 'bool &'
- // template< typename type, type cvrefvalue = b >
- // ^
- #elif 0
- // try to bind to non-type template parameter
- template< typename type, std::decay_t< type > value = std::decay_t< type >{}, type cvrefvalue = value >
- #elif 0
- template< typename type, type cvrefvalue{} >
- #elif 0
- template< typename type, type cvrefvalue = {} >
- #else
- template< typename type, type cvrefvalue = std::decay_t< type >{} >
- #endif
- struct test
- {
- static_assert(std::is_rvalue_reference< type >{} == std::is_rvalue_reference< decltype(cvrefvalue) >{});
- static_assert(std::is_lvalue_reference< type >{} == std::is_lvalue_reference< decltype(cvrefvalue) >{});
- using lhs = std::remove_reference_t< type >;
- using rhs = std::remove_reference_t< decltype(cvrefvalue) >;
- //static_assert(std::is_const< lhs >{} == std::is_const< rhs >{}); // not true for cv-qualified `type`
- //static_assert(std::is_volatile< lhs >{} == std::is_volatile< rhs >{}); // not true for cv-qualified `type`
- static_assert(!std::is_const< rhs >{});
- static_assert(!std::is_volatile< rhs >{});
- };
- }
- int
- main()
- {
- #if 0
- using T = struct {}; // a non-type template parameter cannot be class
- #elif 0
- struct T {}; // a non-type template parameter cannot be class
- #else
- using T = bool;
- #endif
- static_assert(std::is_default_constructible< T >{}); // only the requirements
- // value
- #if 0
- static_cast< void >(test< T >{});
- #endif
- // v-qualified value
- #if 0
- static_cast< void >(test< volatile T >{});
- #endif
- // c(v)-qualified values
- #if 1
- static_cast< void >(test< T const >{});
- static_cast< void >(test< volatile T const >{});
- #endif
- // references for (cv-qualified) values
- #if 0
- static_cast< void >(test< T & >{});
- static_cast< void >(test< T const & >{});
- static_cast< void >(test< volatile T & >{});
- static_cast< void >(test< volatile T const & >{});
- static_cast< void >(test< T && >{});
- static_cast< void >(test< T const && >{});
- static_cast< void >(test< volatile T && >{});
- static_cast< void >(test< volatile T const && >{});
- #endif
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment