2021-08-19 15:00:44 +02:00
|
|
|
#ifndef BWIDGETS_CONCEPTS_HPP
|
|
|
|
#define BWIDGETS_CONCEPTS_HPP
|
2021-07-18 18:26:12 +02:00
|
|
|
|
2021-07-20 15:20:46 +02:00
|
|
|
#include <string>
|
2021-07-18 18:26:12 +02:00
|
|
|
#include <type_traits>
|
|
|
|
|
2021-08-06 14:22:56 +02:00
|
|
|
namespace bwidgets
|
2021-07-18 18:26:12 +02:00
|
|
|
{
|
2021-08-23 23:50:14 +02:00
|
|
|
// T can be converted to string with to_string.
|
2021-07-20 15:20:46 +02:00
|
|
|
template<typename T>
|
2021-07-29 16:06:03 +02:00
|
|
|
concept CanToString = requires(T value)
|
|
|
|
{
|
|
|
|
std::to_string(value);
|
|
|
|
};
|
2021-07-20 15:20:46 +02:00
|
|
|
|
2021-08-23 23:50:14 +02:00
|
|
|
// T is a floating point type.
|
2021-08-06 14:22:56 +02:00
|
|
|
template<typename T>
|
|
|
|
concept FloatingPoint = std::is_floating_point_v<T>;
|
|
|
|
|
2021-08-23 23:50:14 +02:00
|
|
|
// T can be any numeric type.
|
2021-07-18 18:26:12 +02:00
|
|
|
template<typename T>
|
|
|
|
concept Numeric = std::is_arithmetic_v<T>;
|
2021-07-20 15:20:46 +02:00
|
|
|
|
2021-08-23 23:50:14 +02:00
|
|
|
// T can be converted to string by using ostream.
|
2021-07-20 15:20:46 +02:00
|
|
|
template<typename T>
|
2021-07-29 16:06:03 +02:00
|
|
|
concept Printable = requires(T value)
|
|
|
|
{
|
|
|
|
std::declval<std::ostream&>() << value;
|
|
|
|
};
|
2021-07-18 18:26:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|