Loading...
Searching...
No Matches
attribute_value.h
Go to the documentation of this file.
1#ifndef _BBM_ATTRIBUTE_VALUE_H_
2#define _BBM_ATTRIBUTE_VALUE_H_
3
5
6/************************************************************************/
7/*! \file attribute_value.h
8
9 \brief Helper methods for extracting the value of an attribute (according to
10 concepts::attribute).
11
12*************************************************************************/
13
14namespace bbm {
15
16 /**********************************************************************/
17 /*! \brief return the value of an attribute, or if not an attribute the object
18 *********************************************************************/
19 template<typename T>
20 decltype(auto) value(T&& t)
21 {
22 if constexpr (concepts::attribute<std::decay_t<T>>) return t.value();
23 else return t;
24 }
25
26
27 /*** Implementation detail ***/
28 namespace detail {
29 template<typename T> struct attribute_value { using type = T; };
30 template<typename T> requires bbm::concepts::attribute<T>
31 struct attribute_value<T>
32 {
33 using type = typename std::decay_t<T>::type;
34 };
35 } // end detail namespace
36
37 /**********************************************************************/
38 /*! \brief return the type of value(t)
39 **********************************************************************/
40 template<typename T>
41 using attribute_value_t = bbm::detail::attribute_value<std::decay_t<T>>::type;
42
43} // end bbm namespace
44
45#endif /* _BBM_ATTRIBUTE_VALUE_H_ */
attribute concept
Definition: attribute.h:39
attribute and attribute_property contracts
Definition: aggregatebsdf.h:29
bbm::detail::attribute_value< std::decay_t< T > >::type attribute_value_t
return the type of value(t)
Definition: attribute_value.h:41
decltype(auto) value(T &&t)
return the value of an attribute, or if not an attribute the object
Definition: attribute_value.h:20