concepts.hpp
Go to the documentation of this file.
1 //
2 // Copyright (C) 2014, 2015 Ableton AG, Berlin. All rights reserved.
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a
5 // copy of this software and associated documentation files (the "Software"),
6 // to deal in the Software without restriction, including without limitation
7 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 // and/or sell copies of the Software, and to permit persons to whom the
9 // Software is furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 // DEALINGS IN THE SOFTWARE.
21 //
22 
27 #pragma once
28 
29 #include <atria/meta/concept.hpp>
32 #include <utility>
33 #include <cassert>
34 
35 namespace atria {
36 namespace funken {
37 
38 template <typename T>
39 auto declval_() -> typename std::add_rvalue_reference<T>::type
40 {
41  assert(!"You should never run this function!");
42  return *static_cast<estd::decay_t<T>*>(nullptr);
43 }
44 
49 {
50  template <typename T,
51  typename V = meta::value_t<T> >
52  auto requires_(T&& x, V& v = declval_<V&>()) -> decltype(
54  v = x.get(),
55  v = static_cast<const T&&>(x).get()));
56 };
57 
61 ABL_CONCEPT_SPEC(Out_value)
62 {
63  template <typename T,
64  typename V = meta::value_t<T> >
65  auto requires_(T&& x, V& v = declval_<V&>()) -> decltype(
67  (x.set(v), meta::can_be_void),
68  (x.set(static_cast<const V&&>(v)), meta::can_be_void)));
69 };
70 
76 ABL_CONCEPT_SPEC(Inout_value)
77 {
78  template <typename T>
79  auto requires_(T&& x) -> decltype(
81  meta::require<(In_value<T>())>(),
82  meta::require<(Out_value<T>())>()));
83 };
84 
88 ABL_CONCEPT_SPEC(Root_value)
89 {
90  template <typename T>
91  auto requires_(T&& x) -> decltype(
93  (commit(x), meta::can_be_void)));
94 };
95 
96 } // namespace funken
97 } // namespace atria
Utility classes for definining and using concepts lite in C++11.
eval_t< get_value_type< estd::decay_t< T > > > value_t
Convenient alias for get_value_type
Definition: value_type.hpp:76
constexpr int can_be_void
Use to allow a void expression by chaining it in a comma operator thing.
Definition: utils.hpp:103
estd::enable_if_t< Requirement, int > require
Utility to define concepts in terms of other concepts or other kinds boolean requirements.
Definition: concept.hpp:110
void expressions(Ts &&...)
Allows to validate a sequence of expressions in a single decltype.
ABL_CONCEPT_SPEC(In_value)
Concept for objects that provide values via a getter.
Definition: concepts.hpp:48
C++ amazing templates and reusable implementations awesomeness.
Definition: _doc.hpp:35
Fork me on GitHub