Skip to content

Commit

Permalink
Used inline variables for metaprogramming constants
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Jan 17, 2021
1 parent 6d155ce commit 3176c7a
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 65 deletions.
8 changes: 4 additions & 4 deletions src/config_attribute_value.hpp
Expand Up @@ -145,7 +145,7 @@ class config_attribute_value
config_attribute_value& operator=(const std::string &v);
config_attribute_value& operator=(const t_string &v);
template<typename T>
std::enable_if_t<std::is_base_of<enum_tag, T>::value, config_attribute_value&> operator=(const T &v)
std::enable_if_t<std::is_base_of_v<enum_tag, T>, config_attribute_value&> operator=(const T &v)
{
return operator=(T::enum_to_string(v));
}
Expand All @@ -169,7 +169,7 @@ class config_attribute_value
TODO: Fix this in c++11 using constexpr types.
*/
template<typename T>
std::enable_if_t<std::is_base_of<enum_tag, T>::value, T> to_enum(const T &v) const
std::enable_if_t<std::is_base_of_v<enum_tag, T>, T> to_enum(const T &v) const
{
return T::string_to_enum(this->str(), v);
}
Expand Down Expand Up @@ -198,14 +198,14 @@ class config_attribute_value
// These function prevent t_string creation in case of c["a"] == "b" comparisons.
// The templates are needed to prevent using these function in case of c["a"] == 0 comparisons.
template<typename T>
std::enable_if_t<std::is_same<const std::string, std::add_const_t<T>>::value, bool>
std::enable_if_t<std::is_same_v<const std::string, std::add_const_t<T>>, bool>
friend operator==(const config_attribute_value &val, const T &str)
{
return val.equals(str);
}

template<typename T>
std::enable_if_t<std::is_same<const char*, T>::value, bool>
std::enable_if_t<std::is_same_v<const char*, T>, bool>
friend operator==(const config_attribute_value& val, T str)
{
return val.equals(std::string(str));
Expand Down
2 changes: 1 addition & 1 deletion src/formula/variant_value.hpp
Expand Up @@ -433,7 +433,7 @@ class variant_container : public variant_value_base
: container_(container)
{
// NOTE: add more conditions if this changes.
static_assert((std::is_same<variant_vector, T>::value || std::is_same<variant_map_raw, T>::value),
static_assert((std::is_same_v<variant_vector, T> || std::is_same_v<variant_map_raw, T>),
"variant_container only accepts vector or map specifications.");
}

Expand Down
6 changes: 3 additions & 3 deletions src/gui/auxiliary/field.hpp
Expand Up @@ -284,7 +284,7 @@ class field : public field_base
, callback_load_value_(callback_load_value)
, callback_save_value_(callback_save_value)
{
static_assert(!std::is_same<styled_widget, W>::value, "Second template argument cannot be styled_widget");
static_assert(!std::is_same_v<styled_widget, W>, "Second template argument cannot be styled_widget");
}

/**
Expand All @@ -308,7 +308,7 @@ class field : public field_base
, callback_load_value_(nullptr)
, callback_save_value_(nullptr)
{
static_assert(!std::is_same<styled_widget, W>::value, "Second template argument cannot be styled_widget");
static_assert(!std::is_same_v<styled_widget, W>, "Second template argument cannot be styled_widget");
}

/**
Expand All @@ -335,7 +335,7 @@ class field : public field_base
, callback_load_value_(nullptr)
, callback_save_value_(nullptr)
{
static_assert(std::is_same<styled_widget, W>::value, "Second template argument must be styled_widget");
static_assert(std::is_same_v<styled_widget, W>, "Second template argument must be styled_widget");
}

/** Inherited from field_base. */
Expand Down
2 changes: 1 addition & 1 deletion src/gui/core/event/dispatcher_private.hpp
Expand Up @@ -57,7 +57,7 @@ struct dispatcher_implementation
* dispatcher::signal_type<FUNCTION> \
*/ \
template<typename F> \
static std::enable_if_t<std::is_same<F, FUNCTION>::value, dispatcher::signal_type<FUNCTION>>& \
static std::enable_if_t<std::is_same_v<F, FUNCTION>, dispatcher::signal_type<FUNCTION>>& \
event_signal(dispatcher& dispatcher, const ui_event event) \
{ \
return dispatcher.QUEUE.queue[event]; \
Expand Down
4 changes: 2 additions & 2 deletions src/gui/widgets/status_label_helper.hpp
Expand Up @@ -27,7 +27,7 @@ namespace gui2
* Default value getter for selectable widgets (like toggle buttons)
*/
template<typename T>
static inline std::enable_if_t<std::is_base_of<selectable_item, T>::value, std::string>
static inline std::enable_if_t<std::is_base_of_v<selectable_item, T>, std::string>
default_status_value_getter(T& w)
{
return w.get_value_bool() ? _("yes") : _("no");
Expand All @@ -37,7 +37,7 @@ default_status_value_getter(T& w)
* Default value getter for integer-based widgets (like sliders)
*/
template<typename T>
static inline std::enable_if_t<std::is_base_of<integer_selector, T>::value, std::string>
static inline std::enable_if_t<std::is_base_of_v<integer_selector, T>, std::string>
default_status_value_getter(T& w)
{
return w.get_value_label();
Expand Down
8 changes: 4 additions & 4 deletions src/gui/widgets/styled_widget.hpp
Expand Up @@ -32,11 +32,11 @@ struct builder_styled_widget;

/**
* @ingroup GUIWidgetWML
*
*
* Base class for all visible items.
*
*
* All widgets placed in a cell of a grid have some values in common:
* Key |Type |Default |Description
* Key |Type |Default |Description
* -----------------------------|------------------------------------|---------|-----------
* id | @ref guivartype_string "string" |"" |This value is used for the engine to identify 'special' items. This means that for example a text_box can get the proper initial value. This value should be unique or empty. Those special values are documented at the window definition that uses them. NOTE: items starting with an underscore are used for composed widgets and these should be unique per composed widget.
* definition | @ref guivartype_string "string" |"default"|The id of the widget definition to use. This way it's possible to select a specific version of the widget e.g. a title label when the label is used as title.
Expand Down Expand Up @@ -318,7 +318,7 @@ class styled_widget : public widget
template<typename T>
std::shared_ptr<const typename T::resolution> cast_config_to() const
{
static_assert(std::is_base_of<resolution_definition, typename T::resolution>::value,
static_assert(std::is_base_of_v<resolution_definition, typename T::resolution>,
"Given type's resolution object does not derive from resolution_definition."
);

Expand Down
24 changes: 12 additions & 12 deletions src/lexical_cast.hpp
Expand Up @@ -167,7 +167,7 @@ struct lexical_caster<
std::string
, From
, void
, std::enable_if_t<std::is_integral<std::remove_pointer_t<From>>::value>
, std::enable_if_t<std::is_integral_v<std::remove_pointer_t<From>>>
>
{
std::string operator()(From value, std::optional<std::string>) const
Expand All @@ -192,7 +192,7 @@ struct lexical_caster<
long long
, From
, void
, std::enable_if_t<std::is_same<From, const char*>::value || std::is_same<From, char*>::value>
, std::enable_if_t<std::is_same_v<From, const char*> || std::is_same_v<From, char*>>
>
{
long long operator()(From value, std::optional<long long> fallback) const
Expand Down Expand Up @@ -247,8 +247,8 @@ template <class To, class From>
struct lexical_caster<
To
, From
, std::enable_if_t<std::is_integral<To>::value && std::is_signed<To>::value && !std::is_same<To, long long>::value>
, std::enable_if_t<std::is_same<From, const char*>::value || std::is_same<From, char*>::value>
, std::enable_if_t<std::is_integral_v<To> && std::is_signed_v<To> && !std::is_same_v<To, long long>>
, std::enable_if_t<std::is_same_v<From, const char*> || std::is_same_v<From, char*>>
>
{
To operator()(From value, std::optional<To> fallback) const
Expand All @@ -272,7 +272,7 @@ template <class To>
struct lexical_caster<
To
, std::string
, std::enable_if_t<std::is_integral<To>::value && std::is_signed<To>::value && !std::is_same<To, long long>::value>
, std::enable_if_t<std::is_integral_v<To> && std::is_signed_v<To> && !std::is_same_v<To, long long>>
>
{
To operator()(const std::string& value, std::optional<To> fallback) const
Expand Down Expand Up @@ -305,8 +305,8 @@ template <class To, class From>
struct lexical_caster<
To
, From
, std::enable_if_t<std::is_floating_point<To>::value>
, std::enable_if_t<std::is_same<From, const char*>::value || std::is_same<From, char*>::value>
, std::enable_if_t<std::is_floating_point_v<To>>
, std::enable_if_t<std::is_same_v<From, const char*> || std::is_same_v<From, char*>>
>
{
To operator()(From value, std::optional<To> fallback) const
Expand All @@ -330,7 +330,7 @@ template <class To>
struct lexical_caster<
To
, std::string
, std::enable_if_t<std::is_floating_point<To>::value>
, std::enable_if_t<std::is_floating_point_v<To>>
>
{
To operator()(const std::string& value, std::optional<To> fallback) const
Expand Down Expand Up @@ -375,7 +375,7 @@ struct lexical_caster<
unsigned long long
, From
, void
, std::enable_if_t<std::is_same<From, const char*>::value || std::is_same<From, char*>::value>
, std::enable_if_t<std::is_same_v<From, const char*> || std::is_same_v<From, char*>>
>
{
unsigned long long operator()(From value, std::optional<unsigned long long> fallback) const
Expand Down Expand Up @@ -431,8 +431,8 @@ template <class To, class From>
struct lexical_caster<
To
, From
, std::enable_if_t<std::is_unsigned<To>::value && !std::is_same<To, unsigned long long>::value>
, std::enable_if_t<std::is_same<From, const char*>::value || std::is_same<From, char*>::value>
, std::enable_if_t<std::is_unsigned_v<To> && !std::is_same_v<To, unsigned long long>>
, std::enable_if_t<std::is_same_v<From, const char*> || std::is_same_v<From, char*>>
>
{
To operator()(From value, std::optional<To> fallback) const
Expand All @@ -456,7 +456,7 @@ template <class To>
struct lexical_caster<
To
, std::string
, std::enable_if_t<std::is_unsigned<To>::value>
, std::enable_if_t<std::is_unsigned_v<To>>
>
{
To operator()(const std::string& value, std::optional<To> fallback) const
Expand Down

0 comments on commit 3176c7a

Please sign in to comment.