diff --git a/include/boost/mp11.hpp b/include/boost/mp11.hpp index 4060a3f..4241337 100644 --- a/include/boost/mp11.hpp +++ b/include/boost/mp11.hpp @@ -15,5 +15,6 @@ #include #include #include +#include #endif // #ifndef BOOST_MP11_HPP_INCLUDED diff --git a/include/boost/mp11/bind.hpp b/include/boost/mp11/bind.hpp new file mode 100644 index 0000000..f7febf5 --- /dev/null +++ b/include/boost/mp11/bind.hpp @@ -0,0 +1,64 @@ +#ifndef BOOST_MP11_BIND_HPP_INCLUDED +#define BOOST_MP11_BIND_HPP_INCLUDED + +// Copyright 2017 Peter Dimov. +// +// 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 +#include + +namespace boost +{ +namespace mp11 +{ + +template struct mp_arg +{ + template using fn = mp_at_c, I>; +}; + +using _1 = mp_arg<0>; +using _2 = mp_arg<1>; +using _3 = mp_arg<2>; +using _4 = mp_arg<3>; +using _5 = mp_arg<4>; +using _6 = mp_arg<5>; +using _7 = mp_arg<6>; +using _8 = mp_arg<7>; +using _9 = mp_arg<8>; + +template class F, class... T> struct mp_bind; + +namespace detail +{ + +template struct eval_bound_arg +{ + using type = V; +}; + +template struct eval_bound_arg, T...> +{ + using type = typename mp_arg::template fn; +}; + +template class F, class... U, class... T> struct eval_bound_arg, T...> +{ + using type = typename mp_bind::template fn; +}; + +} // namespace detail + +template class F, class... T> struct mp_bind +{ + template using fn = F::type...>; +}; + +} // namespace mp11 +} // namespace boost + +#endif // #ifndef BOOST_MP11_BIND_HPP_INCLUDED diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 4f68b59..cfc1c36 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -102,3 +102,6 @@ run mp_map_insert.cpp : : : $(REQ) ; run mp_map_replace.cpp : : : $(REQ) ; run mp_map_erase.cpp : : : $(REQ) ; run mp_map_update.cpp : : : $(REQ) ; + +# bind +run mp_bind.cpp : : : $(REQ) ; diff --git a/test/mp_bind.cpp b/test/mp_bind.cpp new file mode 100644 index 0000000..19edf31 --- /dev/null +++ b/test/mp_bind.cpp @@ -0,0 +1,106 @@ + +// Copyright 2017 Peter Dimov. +// +// 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 +#include +#include +#include +#include +#include +#include + +struct X1 {}; +struct X2 {}; +struct X3 {}; +struct X4 {}; +struct X5 {}; +struct X6 {}; +struct X7 {}; +struct X8 {}; +struct X9 {}; + +template using add_pointer = typename std::add_pointer::type; + +int main() +{ + using namespace boost::mp11; + + BOOST_TEST_TRAIT_TRUE((std::is_same<_1::fn, X1>)); + BOOST_TEST_TRAIT_TRUE((std::is_same<_1::fn, X1>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same<_2::fn, X2>)); + BOOST_TEST_TRAIT_TRUE((std::is_same<_2::fn, X2>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same<_3::fn, X3>)); + BOOST_TEST_TRAIT_TRUE((std::is_same<_3::fn, X3>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same<_4::fn, X4>)); + BOOST_TEST_TRAIT_TRUE((std::is_same<_4::fn, X4>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same<_5::fn, X5>)); + BOOST_TEST_TRAIT_TRUE((std::is_same<_5::fn, X5>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same<_6::fn, X6>)); + BOOST_TEST_TRAIT_TRUE((std::is_same<_6::fn, X6>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same<_7::fn, X7>)); + BOOST_TEST_TRAIT_TRUE((std::is_same<_7::fn, X7>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same<_8::fn, X8>)); + BOOST_TEST_TRAIT_TRUE((std::is_same<_8::fn, X8>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same<_9::fn, X9>)); + + // + + BOOST_TEST_TRAIT_TRUE((std::is_same::fn, X1*>)); + BOOST_TEST_TRAIT_TRUE((std::is_same::fn, X1*>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same::fn, X2*>)); + BOOST_TEST_TRAIT_TRUE((std::is_same::fn, X2*>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same::fn, X3*>)); + BOOST_TEST_TRAIT_TRUE((std::is_same::fn, X3*>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same::fn, X4*>)); + BOOST_TEST_TRAIT_TRUE((std::is_same::fn, X4*>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same::fn, X5*>)); + BOOST_TEST_TRAIT_TRUE((std::is_same::fn, X5*>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same::fn, X6*>)); + BOOST_TEST_TRAIT_TRUE((std::is_same::fn, X6*>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same::fn, X7*>)); + BOOST_TEST_TRAIT_TRUE((std::is_same::fn, X7*>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same::fn, X8*>)); + BOOST_TEST_TRAIT_TRUE((std::is_same::fn, X8*>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same::fn, X9*>)); + + // + + BOOST_TEST_TRAIT_TRUE((std::is_same< + mp_bind, + mp_bind, + mp_bind, + mp_bind, + mp_bind, + mp_bind, + mp_bind, + mp_bind, + mp_bind + >::fn, std::tuple>)); + + // + + return boost::report_errors(); +}