CNL  2.0.2 (development)
Compositional Numeric Library
to_rep.h
1 
2 // Copyright John McFarlane 2018.
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file ../LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 
7 #if !defined(CNL_IMPL_NUM_TRAITS_TO_REP_H)
8 #define CNL_IMPL_NUM_TRAITS_TO_REP_H
9 
10 #include "../../constant.h"
11 #include "../type_traits/remove_cvref.h"
12 
13 #include <concepts>
14 #include <type_traits>
15 #include <utility>
16 
17 namespace cnl {
18  namespace _impl {
19  template<typename Number>
20  struct default_to_rep {
21  [[nodiscard]] constexpr auto& operator()(Number& n) const
22  {
23  return n;
24  };
25  [[nodiscard]] constexpr auto const& operator()(Number const& n) const
26  {
27  return n;
28  };
29  [[nodiscard]] constexpr auto&& operator()(Number&& n) const
30  {
31  return std::forward<Number>(n);
32  };
33  };
34  }
35 
40  template<typename Number>
41  struct to_rep;
42 
44  template<typename Number>
45  requires(std::is_integral_v<Number> || std::is_floating_point_v<Number> || _impl::is_constant<Number>::value) struct to_rep<Number>
46  : _impl::default_to_rep<Number> {
47  };
49 
50  namespace _impl {
51  template<class Number>
52  [[nodiscard]] constexpr auto to_rep(Number&& n) // NOLINT(misc-unused-parameters)
53  -> decltype(cnl::to_rep<remove_cvref_t<Number>>()(std::forward<Number>(n)))
54  {
55  return cnl::to_rep<remove_cvref_t<Number>>()(std::forward<Number>(n));
56  }
57  }
58 }
59 
60 #endif // CNL_IMPL_NUM_TRAITS_TO_REP_H
cnl
compositional numeric library
Definition: abort.h:15
cnl::to_rep
Returns the value encapsulated in number.
Definition: to_rep.h:41