make.hpp 1.3 KB

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