1 /*============================================================================= 2 Copyright (c) 2017 Nikita Kniazev 3 4 Distributed under the Boost Software License, Version 1.0. (See accompanying 5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 ==============================================================================*/ 7 8 #include <boost/phoenix/core.hpp> 9 #include <boost/phoenix/object.hpp> 10 #include <boost/phoenix/scope.hpp> 11 #include <boost/phoenix/operator.hpp> 12 13 #include <string> 14 #include <iostream> 15 16 template <typename T, std::size_t N> 17 struct array_holder 18 { 19 typedef T underlying_type[N]; 20 array_holderarray_holder21 array_holder(underlying_type const& x) 22 { 23 for (std::size_t i = 0; i < N; ++i) elems_[i] = x[i]; 24 } 25 26 T elems_[N]; 27 operator <<(std::ostream & os,array_holder const & x)28 friend std::ostream& operator<<(std::ostream& os, array_holder const& x) 29 { 30 os << x.elems_[0]; 31 for (std::size_t i = 1; i < N; ++i) os << ", " << x.elems_[i]; 32 return os; 33 } 34 }; 35 main()36int main() 37 { 38 using boost::phoenix::construct; 39 using boost::phoenix::let; 40 using boost::phoenix::arg_names::_1; 41 using boost::phoenix::local_names::_a; 42 43 let(_a = construct<std::string>("str")) 44 [ 45 std::cout << _a << std::endl 46 ](); 47 48 let(_a = construct<array_holder<char, 4> >("str")) 49 [ 50 std::cout << _a << std::endl 51 ](); 52 53 int ints[] = { 1, 2, 3 }; 54 let(_a = construct<array_holder<int, sizeof(ints) / sizeof(ints[0])> >(ints) ) 55 [ 56 std::cout << _a << std::endl 57 ](); 58 59 return 0; 60 } 61