-
Notifications
You must be signed in to change notification settings - Fork 2
plusValue
Igor Zarzycki edited this page Jan 25, 2022
·
1 revision
Defined in "crap/functional.d/plusvalue.h".
Defined in "crap/functional".
template <class Type, Type ... Values> struct plusValue;
Returns sum of Values...
. Order of computations is unspecified.
-
Type
- type of values to operate on. -
Values...
- set of values to operate on.
-
value
- holds result of operation. IfValues...
is single element,value
holds that element. IfValues...
is empty,value
holds value ofzero
(see zero) forType
.
-
value_type
- type of fieldvalue
. May not beType
but should be castable to this type.
-
constexpr operator value_type () const noexcept
- casts whole object to itsvalue_type
returningvalue
.
#include <crap/functional.d/plusvalue.h>
int main()
{
static_assert(crap :: plusValue<unsigned int>{} == 0u, "zero should be 0");
static_assert(crap :: plusValue<unsigned int, 42u>{} == 42u, "42 should be 42");
static_assert(crap :: plusValue<unsigned int, 22u, 20u>{} == 42u, "22 + 20 should be 42");
static_assert(crap :: plusValue<unsigned int, 42u, 0u>{} == 42u, "42 + 0 should be 42");
static_assert(crap :: plusValue<unsigned int, 10u, 12, 20u>{} == (10u + 12u + 20u),
"10 + 12 + 20 should be 42");
static_assert(crap :: plusValue<unsigned int, 20u, 0u, 0u, 0u, 0u, 0u, 0u, 22u>{} == 42u,
"anything plus 0 remains seme so rest should be 42");
return 0;
}