]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*! |
2 | @file | |
3 | Defines `boost::hana::make`. | |
4 | ||
5 | @copyright Louis Dionne 2013-2016 | |
6 | Distributed under the Boost Software License, Version 1.0. | |
7 | (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) | |
8 | */ | |
9 | ||
10 | #ifndef BOOST_HANA_CORE_MAKE_HPP | |
11 | #define BOOST_HANA_CORE_MAKE_HPP | |
12 | ||
13 | #include <boost/hana/fwd/core/make.hpp> | |
14 | ||
15 | #include <boost/hana/config.hpp> | |
16 | #include <boost/hana/core/default.hpp> | |
17 | #include <boost/hana/core/when.hpp> | |
18 | ||
19 | ||
20 | BOOST_HANA_NAMESPACE_BEGIN | |
21 | //! @cond | |
22 | template <typename Datatype, typename> | |
23 | struct make_impl : make_impl<Datatype, when<true>> { }; | |
24 | //! @endcond | |
25 | ||
26 | template <typename Datatype, bool condition> | |
27 | struct make_impl<Datatype, when<condition>> : default_ { | |
28 | template <typename ...X> | |
29 | static constexpr auto make_helper(int, X&& ...x) | |
30 | -> decltype(Datatype(static_cast<X&&>(x)...)) | |
31 | { return Datatype(static_cast<X&&>(x)...); } | |
32 | ||
33 | template <typename ...X> | |
34 | static constexpr auto make_helper(long, X&& ...) { | |
35 | static_assert((sizeof...(X), false), | |
36 | "there exists no constructor for the given data type"); | |
37 | } | |
38 | ||
39 | template <typename ...X> | |
40 | static constexpr decltype(auto) apply(X&& ...x) | |
41 | { return make_helper(int{}, static_cast<X&&>(x)...); } | |
42 | }; | |
43 | BOOST_HANA_NAMESPACE_END | |
44 | ||
45 | #endif // !BOOST_HANA_CORE_MAKE_HPP |