diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 7bc75bfae..0f2e2b51c 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -53,3 +53,5 @@ boost_hana_add_example(list.take_until) boost_hana_add_example(list.take_while) boost_hana_add_example(list.zip) boost_hana_add_example(list.zip_with) + +boost_hana_add_example(type.untype) diff --git a/example/type/untype.cpp b/example/type/untype.cpp new file mode 100644 index 000000000..261a6a85f --- /dev/null +++ b/example/type/untype.cpp @@ -0,0 +1,21 @@ +/* +@copyright Louis Dionne 2014 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ + +#include +#include +#include + +#include +using namespace boost::hana; + + +int main() { + //! [main] + struct T; + BOOST_HANA_CONSTEXPR_LAMBDA auto t = type; + BOOST_HANA_STATIC_ASSERT(std::is_same, T>{}); + //! [main] +} diff --git a/include/boost/hana/type.hpp b/include/boost/hana/type.hpp index 656cf1049..fa1000ca6 100644 --- a/include/boost/hana/type.hpp +++ b/include/boost/hana/type.hpp @@ -45,18 +45,29 @@ namespace boost { namespace hana { return wrapper{}; }(); +#if defined(BOOST_HANA_DOXYGEN_INVOKED) //! Metafunction returning the type represented by a `Type`. //! @relates Type //! - //! @note This operation is the inverse of `type`. + //! This operation is the inverse of `type`. It must be a metafunction + //! because if it were a function, it would have to return an object, + //! which is not always possible (consider uninhabited types). //! - //! @todo Explain why this must be a metafunction, with examples. + //! ### Example + //! @snippet example/type/untype.cpp main + //! + //! @internal + //! internal: Keep this an alias so it stays grouped with `Type` in + //! the documentation. + template + using untype = unspecified; +#else template struct untype { using type = typename T::hidden; }; +#endif - //! Alias to `untype::type`; provided for convenience. //! @relates Type template using untype_t = typename untype::type;