CNL  2.0.2 (development)
Compositional Numeric Library
from_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_FROM_REP_H)
8 #define CNL_IMPL_NUM_TRAITS_FROM_REP_H
9 
10 #include <concepts>
11 
12 namespace cnl {
20  template<typename Number, typename Rep>
21  struct from_rep;
22 
29  template<std::integral Number, typename Rep>
30  struct from_rep<Number, Rep> {
31  [[nodiscard]] constexpr auto operator()(Rep const& rep) const
32  {
33  // by default, a number type's rep type is the number type itself
34  return static_cast<Number>(rep);
35  }
36  };
37 
38  namespace _impl {
39  template<class Number, class Rep>
40  [[nodiscard]] constexpr auto from_rep(Rep const& rep)
41  {
42  return cnl::from_rep<Number, Rep>{}(rep);
43  }
44  }
45 }
46 
47 #endif // CNL_IMPL_NUM_TRAITS_FROM_REP_H
cnl::from_rep< Number, Rep >
Specialization of from_rep for integer types.
Definition: from_rep.h:30
cnl::from_rep
generic function object that returns the number encapsulating a given value
Definition: from_rep.h:21
cnl
compositional numeric library
Definition: abort.h:15