]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/proto/test/cpp-next_bug.cpp
1 ///////////////////////////////////////////////////////////////////////////////
4 // Copyright 2012 Eric Niebler. Distributed under the Boost
5 // Software License, Version 1.0. (See accompanying file
6 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 #include <boost/proto/proto.hpp>
10 #include <boost/test/unit_test.hpp>
11 namespace mpl
= boost::mpl
;
12 namespace proto
= boost::proto
;
15 namespace linear_algebra
17 // A trait that returns true only for std::vector
23 template<typename T
, typename A
>
24 struct is_std_vector
<std::vector
<T
, A
> >
28 // A type used as a domain for linear algebra expressions
29 struct linear_algebra_domain
33 // Define all the operator overloads for combining std::vectors
34 BOOST_PROTO_DEFINE_OPERATORS(is_std_vector
, linear_algebra_domain
)
36 // Take any expression and turn each node
37 // into a subscript expression, using the
41 proto::when
<proto::terminal
<_
>, proto::_make_subscript(_
, proto::_state
)>
42 , proto::plus
<Distribute
, Distribute
>
49 proto::subscript
<Distribute
, proto::terminal
<_
> >,
50 Distribute(proto::_left
, proto::_right
)
52 , proto::plus
<Optimize
, Optimize
>
58 static const int celems
= 4;
59 static int const value
[celems
] = {1,2,3,4};
60 std::vector
<int> A(value
, value
+celems
), B(A
);
64 using namespace linear_algebra
;
65 proto::_default
<> eval
;
66 BOOST_CHECK_EQUAL(8, eval(Optimize()((A
+ B
)[3])));
69 using namespace boost::unit_test
;
70 ///////////////////////////////////////////////////////////////////////////////
71 // init_unit_test_suite
73 test_suite
* init_unit_test_suite( int argc
, char* argv
[] )
75 test_suite
*test
= BOOST_TEST_SUITE("test for a problem reported on the cpp-next.com blog");
77 test
->add(BOOST_TEST_CASE(&test1
));