-
Notifications
You must be signed in to change notification settings - Fork 2
arithmeticOperatorsForType::Divides(struct)
Igor Zarzycki edited this page Jan 31, 2022
·
3 revisions
Defined in "crap/functional.d/arithmeticoperatorsfortype.h".
Defined in "crap/functional".
template <class Type>
struct arithmeticOperatorsForType
{
/*...*/
template <Type ... Values>
using Divides = dividesValue<Type, Values...>;
/*...*/
};
Creates dividesValue
(see dividesValue) acting on type Type
. Allows for dividesValue
to act as value operator.
-
Values...
- values to operate on.
-
value
- holds result of operation. IfValues...
is single element, value holds that element. IfValues...
is empty whole operation is not defined.
-
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/arithmeticoperatorsfortype.h>
int main()
{
static_assert(crap :: arithmeticOperatorsForType <unsigned int> :: template Divides<42u>{} == 42u, "42 should be 42");
static_assert(crap :: arithmeticOperatorsForType <unsigned int> :: template Divides<42u, 42u>{} == 1u, "42 / 42 should be 1");
static_assert(crap :: arithmeticOperatorsForType <unsigned int> :: template Divides<42u, 6u>{} == 7u, "42 / 6 should be 7");
static_assert(crap :: arithmeticOperatorsForType <unsigned int> :: template Divides<42u, 101u>{} == (42u / 101u), "42 / 101 should be 0");
static_assert(crap :: arithmeticOperatorsForType <unsigned int> :: template Divides<42u, 6u, 3u>{} == ((42u / 6u) / 3u),
"42 / 6 / 3 should be 2");
static_assert(crap :: arithmeticOperatorsForType<unsigned int> :: template Divides<85u, 2u, 7u, 3u, 2u>{} == ((((85u / 2u) / 7u) / 3u) / 2u),
" 85 / 2 is 42 so rest should be 1");
return 0;
}