funcy  1.6.1
identity.h
1 #pragma once
2 
3 #include <funcy/util/chainer.h>
4 
5 #include <type_traits>
6 #include <utility>
7 
8 namespace funcy
9 {
11  template < class Arg >
12  struct Identity : Chainer< Identity< Arg > >
13  {
15  Identity() = default;
16 
21  Identity( const Arg& x ) noexcept( std::is_copy_constructible_v< Arg > ) : x_( x )
22  {
23  }
24 
29  Identity( Arg&& x ) noexcept( std::is_move_constructible_v< Arg > ) : x_( std::move( x ) )
30  {
31  }
32 
34  void update( const Arg& x )
35  {
36  x_ = x;
37  }
38 
40  const Arg& d0() const noexcept
41  {
42  return x_;
43  }
44 
46  template < int >
47  const Arg& d1( const Arg& dx ) const noexcept
48  {
49  return dx;
50  }
51 
52  private:
53  Arg x_;
54  };
55 
57  template < class Arg >
58  auto identity( Arg&& x )
59  {
60  return Identity( std::forward< Arg >( x ) );
61  }
62 } // namespace funcy
void update(const Arg &x)
Reset point of evaluation.
Definition: identity.h:34
auto identity(Arg &&x)
Construct Identity<Arg>(x).
Definition: identity.h:58
Identity()=default
Default constructor.
const Arg & d0() const noexcept
Function value.
Definition: identity.h:40
Identity(Arg &&x) noexcept(std::is_move_constructible_v< Arg >)
Constructor.
Definition: identity.h:29
Identity(const Arg &x) noexcept(std::is_copy_constructible_v< Arg >)
Constructor.
Definition: identity.h:21
Main namespace of the funcy library.
Identity mapping .
Definition: identity.h:12
const Arg & d1(const Arg &dx) const noexcept
First directional derivative.
Definition: identity.h:47