arithmeticOperatorsForType::Plus(struct) - HaxyM/crap GitHub Wiki

crap :: arithmeticOperatorsForType :: Plus

Defined in "crap/functional.d/arithmeticoperatorsfortype.h".
Defined in "crap/functional".


template <class Type>
struct arithmeticOperatorsForType
{
 /*...*/
 template <Type ... Values>
 using Plus = plusValue<Type, Values...>;
 /*...*/
};

Creates plusValue (see plusValue) acting on type Type. Allows for plusValue to act as value operator.

Template parameters

  • Values... - 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/arithmeticoperatorsfortype.h>

int main()
{
 static_assert(crap :: arithmeticOperatorsForType <unsigned int> :: template Plus<>{} == 0u, "zero should be 0");
 static_assert(crap :: arithmeticOperatorsForType <unsigned int> :: template Plus<42u>{} == 42u, "42 should be 42");
 static_assert(crap :: arithmeticOperatorsForType <unsigned int> :: template Plus<22u, 20u>{} == 42u, "22 + 20 should be 42");
 static_assert(crap :: arithmeticOperatorsForType <unsigned int> :: template Plus<42u, 0u>{} == 42u, "42 + 0 should be 42");
 static_assert(crap :: arithmeticOperatorsForType <unsigned int> :: template Plus<10u, 12u, 20u>{} == (10u + 12u + 20u),
 "10 + 12 + 20 should be 42");
 static_assert(crap :: arithmeticOperatorsForType <unsigned int> :: template Plus<20u, 0u, 0u, 0u, 0u, 0u, 0u, 22u>{} == 42u,
 "anything plus 0 remains seme so rest should be 42");
 return 0;
}

See also

⚠️ **GitHub.com Fallback** ⚠️