Skip to content

plusValue

Igor Zarzycki edited this page Jan 25, 2022 · 1 revision

crap :: plusValue

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.

Template parameters

  • Type - type of values to operate on.
  • Values... - set of values to operate on.

Layout

Member constants

  • value - holds result of operation. If Values... is single element, value holds that element. If Values... is empty, value holds value of zero (see zero) for Type.

Member types

  • value_type - type of field value. May not be Type but should be castable to this type.

Member functions

  • constexpr operator value_type () const noexcept - casts whole object to its value_type returning value.

Usage example

#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;
}

See also

Clone this wiki locally