Calico
 All Classes Namespaces Files Functions Variables Typedefs Friends Groups
lens.hpp File Reference

Lenses are proxy objects that allow a value to be accessed and mutated via a pair of functions ("get" and "put"). More...

#include <type_traits>
#include <utility>

Classes

struct  cal::lens_base< Lens, T >
 CRTP base type for constructing Lens types. More...
 
struct  cal::lens_traits< Lens >
 Traits class for the Lens concept. More...
 
struct  cal::negating_lens< Lens, T >
 A lens that negates the value before storing or accessing it. More...
 
struct  cal::scaling_lens< Lens, Factor, T >
 A lens that scales the value by a factor before storing or accessing it. More...
 

Namespaces

 cal
 Primary namespace.
 

Functions

template<class T >
negating_lens< T > cal::make_negating_lens (T &&x)
 Constructs a negating_lens from a given value.
 
template<class T , class U >
scaling_lens< T, U > cal::make_scaling_lens (T &&lens, U &&factor)
 Constructs a scaling_lens from a given value.
 

Detailed Description

Lenses are proxy objects that allow a value to be accessed and mutated via a pair of functions ("get" and "put").

The concept is named after the Haskell lens package. Lenses are not required to be Copyable, only Movable. They must allow the following operations:

// This is the "get" function ("getter").
operator Lens::value_type() const;
// This is the "put" function ("setter").
Lens& operator=(const Lens::value_type& x);
// This is the rvalue-version of the "put" function (optional).
Lens& operator=(T&& x);