diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/proto/test/make.cpp | |
parent | Initial commit. (diff) | |
download | ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/proto/test/make.cpp')
-rw-r--r-- | src/boost/libs/proto/test/make.cpp | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/src/boost/libs/proto/test/make.cpp b/src/boost/libs/proto/test/make.cpp new file mode 100644 index 00000000..17675aa2 --- /dev/null +++ b/src/boost/libs/proto/test/make.cpp @@ -0,0 +1,98 @@ +/////////////////////////////////////////////////////////////////////////////// +// make.hpp +// +// Copyright 2008 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/proto/core.hpp> +#include <boost/proto/transform/arg.hpp> +#include <boost/proto/transform/make.hpp> +#include <boost/mpl/identity.hpp> +#include <boost/test/unit_test.hpp> + +namespace mpl = boost::mpl; +namespace proto = boost::proto; +using proto::_; + +template<typename T> +struct type2type {}; + +template<typename T> +struct wrapper +{ + T t_; + explicit wrapper(T const & t = T()) : t_(t) {} +}; + +template<typename T> +struct careful +{ + typedef typename T::not_there not_there; +}; + +// Test that when no substitution is done, we don't instantiate templates +struct MakeTest1 + : proto::make< type2type< careful<int> > > +{}; + +void make_test1() +{ + proto::terminal<int>::type i = {42}; + type2type< careful<int> > res = MakeTest1()(i); +} + +// Test that when substitution is done, and there is no nested ::type +// typedef, the result is the wrapper +struct MakeTest2 + : proto::make< wrapper< proto::_value > > +{}; + +void make_test2() +{ + proto::terminal<int>::type i = {42}; + wrapper<int> res = MakeTest2()(i); + BOOST_CHECK_EQUAL(res.t_, 0); +} + +// Test that when substitution is done, and there is no nested ::type +// typedef, the result is the wrapper +struct MakeTest3 + : proto::make< wrapper< proto::_value >(proto::_value) > +{}; + +void make_test3() +{ + proto::terminal<int>::type i = {42}; + wrapper<int> res = MakeTest3()(i); + BOOST_CHECK_EQUAL(res.t_, 42); +} + +// Test that when substitution is done, and there is no nested ::type +// typedef, the result is the wrapper +struct MakeTest4 + : proto::make< mpl::identity< proto::_value >(proto::_value) > +{}; + +void make_test4() +{ + proto::terminal<int>::type i = {42}; + int res = MakeTest4()(i); + BOOST_CHECK_EQUAL(res, 42); +} + +using namespace boost::unit_test; +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("test the make transform"); + + test->add(BOOST_TEST_CASE(&make_test1)); + test->add(BOOST_TEST_CASE(&make_test2)); + test->add(BOOST_TEST_CASE(&make_test3)); + test->add(BOOST_TEST_CASE(&make_test4)); + + return test; +} |