Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:04

0001 /*!
0002 @file
0003 Defines `boost::hana::one`.
0004 
0005 Copyright Louis Dionne 2013-2022
0006 Distributed under the Boost Software License, Version 1.0.
0007 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
0008  */
0009 
0010 #ifndef BOOST_HANA_ONE_HPP
0011 #define BOOST_HANA_ONE_HPP
0012 
0013 #include <boost/hana/fwd/one.hpp>
0014 
0015 #include <boost/hana/concept/constant.hpp>
0016 #include <boost/hana/concept/ring.hpp>
0017 #include <boost/hana/config.hpp>
0018 #include <boost/hana/core/to.hpp>
0019 #include <boost/hana/core/dispatch.hpp>
0020 #include <boost/hana/detail/canonical_constant.hpp>
0021 
0022 #include <type_traits>
0023 
0024 
0025 namespace boost { namespace hana {
0026     //! @cond
0027     template <typename R>
0028     constexpr decltype(auto) one_t<R>::operator()() const {
0029     #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0030         static_assert(hana::Ring<R>::value,
0031         "hana::one<R>() requires 'R' to be a Ring");
0032     #endif
0033 
0034         using One = BOOST_HANA_DISPATCH_IF(one_impl<R>,
0035             hana::Ring<R>::value
0036         );
0037 
0038         return One::apply();
0039     }
0040     //! @endcond
0041 
0042     template <typename R, bool condition>
0043     struct one_impl<R, when<condition>> : default_ {
0044         template <typename ...Args>
0045         static constexpr auto apply(Args&& ...) = delete;
0046     };
0047 
0048     //////////////////////////////////////////////////////////////////////////
0049     // Model for non-boolean arithmetic data types
0050     //////////////////////////////////////////////////////////////////////////
0051     template <typename T>
0052     struct one_impl<T, when<std::is_arithmetic<T>::value &&
0053                             !std::is_same<bool, T>::value>> {
0054         static constexpr T apply()
0055         { return static_cast<T>(1); }
0056     };
0057 
0058     //////////////////////////////////////////////////////////////////////////
0059     // Model for Constants over a Ring
0060     //////////////////////////////////////////////////////////////////////////
0061     namespace detail {
0062         template <typename C>
0063         struct constant_from_one {
0064             static constexpr auto value = hana::one<typename C::value_type>();
0065             using hana_tag = detail::CanonicalConstant<typename C::value_type>;
0066         };
0067     }
0068 
0069     template <typename C>
0070     struct one_impl<C, when<
0071         hana::Constant<C>::value &&
0072         Ring<typename C::value_type>::value
0073     >> {
0074         static constexpr decltype(auto) apply()
0075         { return hana::to<C>(detail::constant_from_one<C>{}); }
0076     };
0077 }} // end namespace boost::hana
0078 
0079 #endif // !BOOST_HANA_ONE_HPP