arithmeticOperatorsForType - HaxyM/crap GitHub Wiki

crap :: arithmeticForType

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


template <class Type>
struct arithmeticOperatorsForType;

Creates dividesValue (see dividesValue), minusValue (see minusValue), modulusValue (see modulusValue), multipliesValue (see multipliesValue), negateValue (see negateValue) and plusValue (see plusValue) acting on type Type. Allows for negateValue as unary value operator and dividesValue, minusValue, modulusValue, multipliesValue, plusValue to act as both value operator and binary value operator.

Template parameters

  • Type - type of values to operate on.

Layout

Member constants

Member types

Usage example

#include <crap/functional.d/arithmeticoperatorsfortype.h>

int main()
{
 using test1 = typename crap :: arithmeticOperatorsForType <unsigned int> :: template Divides<128u, 42u, 3u>;
 using test2 = typename crap :: arithmeticOperatorsForType <unsigned int> :: template Minus<101u, 42u, 17u>;
 using test3 = typename crap :: arithmeticOperatorsForType <unsigned int> :: template Modulus<42u, 35u, 3u>;
 using test4 = typename crap :: arithmeticOperatorsForType <unsigned int> :: template Multiplues<2u, 3u, 7u>;
 using test5 = typename crap :: arithmeticOperatorsForType <  signed int> :: template Negate<-42>;
 using test6 = typename crap :: arithmeticOperatorsForType <unsigned int> :: template Plus<101u, 42u, 27u>;
 using test7 = typename crap :: arithmeticOperatorsForType <unsigned int> :: template Divides2<101u, 42u>;
 using test8 = typename crap :: arithmeticOperatorsForType <unsigned int> :: template Minus2<101u, 42u>;
 using test9 = typename crap :: arithmeticOperatorsForType <unsigned int> :: template Modulus2<101u, 42u>;
 using testA = typename crap :: arithmeticOperatorsForType <unsigned int> :: template Multiplues2<101u, 42u>;
 using testB = typename crap :: arithmeticOperatorsForType <unsigned int> :: template Plus2<101u, 42u>;
 static_assert(test1 :: value == 1u, "test1: ((128 / 42) / 3) should be equal to 1.");
 static_assert(test2 :: value == 42u, "test2: ((101 - 42) - 17) sould be equal to 42.");
 static_assert(test3 :: value == 1u, "test3: ((42 % 35) % 3) sould be equal to 1.");
 static_assert(test4 :: value == 42u, "test4: (2 * 3 * 7) should be equal to 42.");
 static_assert(test5 :: value == 42, "test5: -(-42) should be equal to 42.");
 static_assert(test6 :: value == 170u, "test6: (101 + 42 + 27) should not be equal to 170.");
 static_assert(test7 :: value == 2u, "test7: (101 / 42) should be equal to 2.");
 static_assert(test8 :: value == 59u, "test8: (101 - 42) sould be equal to 59.");
 static_assert(test9 :: value == 17u, "test9: (101 % 42) sould be equal to 17.");
 static_assert(testA :: value == 4242u, "testA: (101 * 42) should be equal to 4242.");
 static_assert(testB :: value == 143u, "testB: (101 + 42) should not be equal to 143.");
 return 0;
}

See also

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