nested_typedef.cpp 1012 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright (C) 2006 Peder Holt
  2. // Use, modification and distribution is subject to the Boost Software
  3. // License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt)
  4. #include <boost/typeof/typeof.hpp>
  5. #include <boost/type_traits/is_same.hpp>
  6. #include <boost/static_assert.hpp>
  7. #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
  8. void do_int(int) {}
  9. struct {
  10. template<typename T>
  11. T operator[](const T& n) {return n;}
  12. } int_p;
  13. template<typename T> struct wrap
  14. {
  15. BOOST_TYPEOF_NESTED_TYPEDEF_TPL(nested,int_p[& do_int])
  16. typedef typename nested::type type;
  17. };
  18. BOOST_TYPEOF_REGISTER_TEMPLATE(wrap,1)
  19. template<typename T> struct parser
  20. {
  21. struct __rule {
  22. static T & a_placeholder;
  23. BOOST_TYPEOF_NESTED_TYPEDEF_TPL(nested,int_p[a_placeholder])
  24. typedef typename nested::type type;
  25. };
  26. };
  27. BOOST_STATIC_ASSERT((boost::is_same<wrap<double>::type,void(*)(int)>::value));
  28. BOOST_STATIC_ASSERT((boost::is_same<parser<wrap<double> >::__rule::type,wrap<double> >::value));