Skip to content

arithmeticOperatorsForType::Multiplies(struct)

Igor Zarzycki edited this page Feb 15, 2022 · 2 revisions

crap :: arithmeticOperatorsForType :: Multiplies

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


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

Creates multipliesValue (see multipliesValue) acting on type Type. Allows for multipliesValue 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 identity (see identity) 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 Multiplies<>{} == 1u, "identity should be 1");
 static_assert(crap :: arithmeticOperatorsForType <unsigned int> :: template Multiplies<42u>{} == 42u, "42 should be 42");
 static_assert(crap :: arithmeticOperatorsForType <unsigned int> :: template Multiplies<6u, 7u>{} == 42u, "6 * 7 should be 42");
 static_assert(crap :: arithmeticOperatorsForType <unsigned int> :: template Multiplies<42u, 1u>{} == 42u, "42 * 1 should be 42");
 static_assert(crap :: arithmeticOperatorsForType <unsigned int> :: template Multiplies<42u, 101u>{} == (42u * 101u), "42 * 101 should be 4242");
 static_assert(crap :: arithmeticOperatorsForType <unsigned int> :: template Multiplies<7u, 6u, 3u>{} == (7u * 6u * 3u),
 "7 * 6 * 3 should be 126");
 static_assert(crap :: arithmeticOperatorsForType <unsigned int> :: template Multiplies<6u, 1u, 1u, 1u, 1u, 1u, 1u, 7u>{} == 42u,
 "anything times 1 remains seme so rest should be 42");
 static_assert(crap :: arithmeticOperatorsForType <unsigned int> :: template Multiplies<85u, 2u, 7u, 3u, 0u>{} == 0u,
 "anything times 0 is 0 so rest should be 0");
 return 0;
}

See also

Clone this wiki locally