70 lines
2.5 KiB
C++
70 lines
2.5 KiB
C++
/**
|
|
This file is a part of our_dick
|
|
Copyright (C) 2022 rexy712
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Affero General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Affero General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef REXY_MATH_SCALAR_HPP
|
|
#define REXY_MATH_SCALAR_HPP
|
|
|
|
#include <type_traits> //is_convertible
|
|
#include <concepts> //convertible_to
|
|
|
|
namespace math{
|
|
|
|
template<class T>
|
|
concept ConvertibleToIntegral =
|
|
std::is_convertible_v<T,bool> ||
|
|
std::is_convertible_v<T,char> ||
|
|
std::is_convertible_v<T,char8_t> ||
|
|
std::is_convertible_v<T,char16_t> ||
|
|
std::is_convertible_v<T,char32_t> ||
|
|
std::is_convertible_v<T,wchar_t> ||
|
|
std::is_convertible_v<T,short> ||
|
|
std::is_convertible_v<T,int> ||
|
|
std::is_convertible_v<T,long> ||
|
|
std::is_convertible_v<T,long long>;
|
|
template<class T>
|
|
concept ConvertibleToFloatingPoint =
|
|
std::is_convertible_v<T,float> ||
|
|
std::is_convertible_v<T,double> ||
|
|
std::is_convertible_v<T,long double>;
|
|
|
|
template<class T>
|
|
concept ConvertibleToArithmetic = ConvertibleToIntegral<T> || ConvertibleToFloatingPoint<T>;
|
|
|
|
|
|
template<class T>
|
|
concept Scalar = ConvertibleToArithmetic<T> && requires(std::decay_t<T> t){
|
|
{t += t} -> std::convertible_to<T>;
|
|
{t -= t} -> std::convertible_to<T>;
|
|
{t /= t} -> std::convertible_to<T>;
|
|
{t *= t} -> std::convertible_to<T>;
|
|
{t + t} -> std::convertible_to<std::decay_t<T>>;
|
|
{t - t} -> std::convertible_to<std::decay_t<T>>;
|
|
{t / t} -> std::convertible_to<std::decay_t<T>>;
|
|
{t * t} -> std::convertible_to<std::decay_t<T>>;
|
|
{-t} -> std::convertible_to<std::decay_t<T>>;
|
|
{t > t} -> std::convertible_to<bool>;
|
|
{t < t} -> std::convertible_to<bool>;
|
|
{t >= t} -> std::convertible_to<bool>;
|
|
{t <= t} -> std::convertible_to<bool>;
|
|
{t == t} -> std::convertible_to<bool>;
|
|
{t != t} -> std::convertible_to<bool>;
|
|
};
|
|
}
|
|
|
|
#endif
|