tuple_from_list.cpp 924 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright Aleksey Gurtovoy 2002-2004
  2. //
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/mpl for documentation.
  8. // $Id$
  9. // $Date$
  10. // $Revision$
  11. #include <boost/mpl/reverse_fold.hpp>
  12. #include <boost/mpl/list.hpp>
  13. #include <boost/tuple/tuple.hpp>
  14. #include <iostream>
  15. using namespace boost::mpl;
  16. template< typename Types > struct tuple_gen
  17. : reverse_fold<
  18. Types
  19. , boost::tuples::null_type
  20. , boost::tuples::cons<_2,_1>
  21. >
  22. {
  23. };
  24. int main()
  25. {
  26. tuple_gen< list<int,char const*,bool> >::type t;
  27. boost::get<0>(t) = -1;
  28. boost::get<1>(t) = "text";
  29. boost::get<2>(t) = false;
  30. std::cout
  31. << boost::get<0>(t) << '\n'
  32. << boost::get<1>(t) << '\n'
  33. << boost::get<2>(t) << '\n'
  34. ;
  35. return 0;
  36. }