CNL  2.0.2 (development)
Compositional Numeric Library
definition.h
Go to the documentation of this file.
1 
2 // Copyright John McFarlane 2019.
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 
9 
10 #if !defined(CNL_IMPL_OPERATORS_GENERIC_OPERATORS_H)
11 #define CNL_IMPL_OPERATORS_GENERIC_OPERATORS_H
12 
13 #include "../../arithmetic.h"
14 #include "../config.h"
15 #include "op.h"
16 #include "tag.h"
17 
18 #include <type_traits>
19 
21 namespace cnl {
22  namespace _impl {
23  struct native_tag;
24 
26  // cnl::_impl::wants_generic_ops
27 
28  // true iff T wants generic operator overloads
29  template<class T>
30  inline constexpr auto wants_generic_ops = false;
31  }
32 
34  // cnl::op_value
35 
39  template<arithmetic Rep, tag Tag = _impl::native_tag>
40  class op_value;
41 
42  namespace _impl {
43  template<typename T>
44  inline constexpr bool is_operand_specialization = false;
45 
46  template<arithmetic Rep, typename Tag>
47  inline constexpr bool is_operand_specialization<op_value<Rep, Tag>> = true;
48 
49  template<typename T>
50  concept operand_specialization = is_operand_specialization<T>;
51  }
52 
54  // generic operators
55 
58  template<_impl::op Operator, _impl::operand_specialization... Operands>
60 
61  template<class ArchetypeTag, typename Initializer>
62  struct deduction;
63 
64  template<_impl::compound_assign_op Operator, class LhsOperand, tag LhsTag, class RhsOperand, tag RhsTag>
65  struct custom_operator<
66  Operator,
67  op_value<LhsOperand, LhsTag>,
68  op_value<RhsOperand, RhsTag>> {
69  constexpr auto& operator()(LhsOperand& lhs, RhsOperand const& rhs) const
70  {
71  using compound_assign_operator = cnl::custom_operator<
73  using compound_assign_operator_result = decltype(compound_assign_operator{}(lhs, rhs));
74  using convert_operator = cnl::custom_operator<
75  _impl::convert_op,
78  return lhs = convert_operator{}(compound_assign_operator{}(lhs, rhs));
79  }
80  };
81 }
82 
83 #endif // CNL_IMPL_OPERATORS_GENERIC_OPERATORS_H
cnl::op_value
operand or result of operation;used as Operands parameter of custom_operator
Definition: definition.h:40
op.h
operators represented as types
cnl
compositional numeric library
Definition: abort.h:15
cnl::custom_operator
customization point for operator overloads
Definition: definition.h:59