| 1 | /*! |
| 2 | @file |
| 3 | Forward declares `boost::hana::make`. |
| 4 | |
| 5 | Copyright Louis Dionne 2013-2022 |
| 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_FWD_CORE_MAKE_HPP |
| 11 | #define BOOST_HANA_FWD_CORE_MAKE_HPP |
| 12 | |
| 13 | #include <boost/hana/config.hpp> |
| 14 | |
| 15 | |
| 16 | namespace boost { namespace hana { |
| 17 | //! @ingroup group-core |
| 18 | //! Create an object of the given tag with the given arguments. |
| 19 | //! |
| 20 | //! This function serves the same purpose as constructors in usual C++. |
| 21 | //! However, instead of creating an object of a specific C++ type, it |
| 22 | //! creates an object of a specific tag, regardless of the C++ type |
| 23 | //! of that object. |
| 24 | //! |
| 25 | //! This function is actually a variable template, so `make<T>` can be |
| 26 | //! passed around as a function object creating an object of tag `T`. |
| 27 | //! Also, it uses tag-dispatching so this is how it should be customized |
| 28 | //! for user-defined tags. |
| 29 | //! |
| 30 | //! Finally, the default implementation of `make` is equivalent to calling |
| 31 | //! the constructor of the given tag with the corresponding arguments. |
| 32 | //! In other words, by default, |
| 33 | //! @code |
| 34 | //! make<T>(args...) == T(args...) |
| 35 | //! @endcode |
| 36 | //! |
| 37 | //! Note that the arguments are perfectly forwarded and the form of |
| 38 | //! construction which is used is exactly as documented, i.e. `T(args...)`. |
| 39 | //! However, if `T(args...)` is not a valid expression, a compilation |
| 40 | //! error is triggered. This default behavior is useful because it makes |
| 41 | //! foreign C++ types that have no notion of tag constructible with `make` |
| 42 | //! out-of-the-box, since their tag is exactly themselves. |
| 43 | //! |
| 44 | //! |
| 45 | //! Example |
| 46 | //! ------- |
| 47 | //! @include example/core/make.cpp |
| 48 | #ifdef BOOST_HANA_DOXYGEN_INVOKED |
| 49 | template <typename Tag> |
| 50 | constexpr auto make = [](auto&& ...x) -> decltype(auto) { |
| 51 | return tag-dispatched; |
| 52 | }; |
| 53 | #else |
| 54 | template <typename Tag, typename = void> |
| 55 | struct make_impl; |
| 56 | |
| 57 | template <typename Tag> |
| 58 | struct make_t { |
| 59 | template <typename ...X> |
| 60 | constexpr decltype(auto) operator()(X&& ...x) const { |
| 61 | return make_impl<Tag>::apply(static_cast<X&&>(x)...); |
| 62 | } |
| 63 | }; |
| 64 | |
| 65 | template <typename Tag> |
| 66 | BOOST_HANA_INLINE_VARIABLE constexpr make_t<Tag> make{}; |
| 67 | #endif |
| 68 | }} // end namespace boost::hana |
| 69 | |
| 70 | #endif // !BOOST_HANA_FWD_CORE_MAKE_HPP |
| 71 | |