/*! @file Defines `boost::hana::one`. @copyright Louis Dionne 2013-2017 Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) */ #ifndef BOOST_HANA_ONE_HPP #define BOOST_HANA_ONE_HPP #include #include #include #include #include #include #include #include namespace boost { namespace hana { //! @cond template constexpr decltype(auto) one_t::operator()() const { #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS static_assert(hana::Ring::value, "hana::one() requires 'R' to be a Ring"); #endif using One = BOOST_HANA_DISPATCH_IF(one_impl, hana::Ring::value ); return One::apply(); } //! @endcond template struct one_impl> : default_ { template static constexpr auto apply(Args&& ...) = delete; }; ////////////////////////////////////////////////////////////////////////// // Model for non-boolean arithmetic data types ////////////////////////////////////////////////////////////////////////// template struct one_impl::value && !std::is_same::value>> { static constexpr T apply() { return static_cast(1); } }; ////////////////////////////////////////////////////////////////////////// // Model for Constants over a Ring ////////////////////////////////////////////////////////////////////////// namespace detail { template struct constant_from_one { static constexpr auto value = hana::one(); using hana_tag = detail::CanonicalConstant; }; } template struct one_impl::value && Ring::value >> { static constexpr decltype(auto) apply() { return hana::to(detail::constant_from_one{}); } }; }} // end namespace boost::hana #endif // !BOOST_HANA_ONE_HPP