Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use concepts even more #5538

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/all_enum_values.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#ifndef CATA_SRC_ALL_ENUM_VALUES_H
#define CATA_SRC_ALL_ENUM_VALUES_H

#include <cstddef>
#include <utility>

#include "enum_traits.h"

template<typename E>
Expand All @@ -24,4 +27,4 @@ auto all_enum_values() -> const std::array<E, num_enum_values<E>()> &
return all_enum_values_helper<E>( std::make_index_sequence<num_enum_values<E>()> {} );
}

#endif // CATA_SRC_ALL_ENUM_VALUES_H
#endif // CATA_SRC_ALL_ENUM_VALUES_H
26 changes: 13 additions & 13 deletions src/assign.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class is_optional_helper<std::optional<T>> : public std::true_type
};
} // namespace detail
template<typename T>
class is_optional : public detail::is_optional_helper<typename std::decay<T>::type>
class is_optional : public detail::is_optional_helper<std::decay_t<T>>
{
};

Expand Down Expand Up @@ -134,9 +134,9 @@ bool assign( const JsonObject &jo, const std::string &name, std::pair<T, T> &val

// Note: is_optional excludes any types based on std::optional, which is
// handled below in a separate function.
template < typename T, typename std::enable_if < std::is_class<T>::value &&!is_optional<T>::value,
int >::type = 0 >
template < typename T>
bool assign( const JsonObject &jo, const std::string &name, T &val, bool strict = false )
requires( std::is_class_v<T> && !is_optional<T>::value ) //*NOPAD*
{
T out;
if( !jo.read( name, out ) ) {
Expand Down Expand Up @@ -363,18 +363,17 @@ bool assign( const JsonObject &jo,

// Kinda hacky way to avoid allowing multiplying temperature
// For example, in 10 * 0 Fahrenheit, 10 * 0 Celsius - what's the expected result of those?
template < typename lvt, typename ut, typename s,
typename std::enable_if_t<units::quantity_details<ut>::common_zero_point::value>* = nullptr>
template < typename lvt, typename ut, typename s>
inline units::quantity<lvt, ut> mult_unit( const JsonObject &, const std::string &,
const units::quantity<lvt, ut> &val, const s scalar )
{
requires units::quantity_details<ut>::common_zero_point::value {
return val * scalar;
}

template < typename lvt, typename ut, typename s,
typename std::enable_if_t < !units::quantity_details<ut>::common_zero_point::value > * = nullptr >
template < typename lvt, typename ut, typename s>
inline units::quantity<lvt, ut> mult_unit( const JsonObject &err, const std::string &name,
const units::quantity<lvt, ut> &, const s )
requires( !units::quantity_details<ut>::common_zero_point::value )
{
err.throw_error( "Multiplying units with multiple scales with different zero points is not well defined",
name );
Expand Down Expand Up @@ -454,16 +453,17 @@ bool assign( const JsonObject &jo,
class time_duration;

template<typename T>
inline typename
std::enable_if<std::is_same<typename std::decay<T>::type, time_duration>::value, bool>::type
inline bool
read_with_factor( const JsonObject &jo, const std::string &name, T &val, const T &factor )
{
requires std::is_same_v<std::decay_t<T>, time_duration> {
int tmp;
if( jo.read( name, tmp, false ) ) {
if( jo.read( name, tmp, false ) )
{
// JSON contained a raw number -> apply factor
val = tmp * factor;
return true;
} else if( jo.has_string( name ) ) {
} else if( jo.has_string( name ) )
{
// JSON contained a time duration string -> no factor
val = read_from_json_string<time_duration>( *jo.get_raw( name ), time_duration::units );
return true;
Expand Down
4 changes: 2 additions & 2 deletions src/cata_utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ double round_up( double val, unsigned int dp );
*
* @p num must be non-negative, @p den must be positive, and @c num+den must not overflow.
*/
template<typename T, typename std::enable_if<std::is_integral<T>::value, int>::type = 0>
template<typename T>
T divide_round_up( T num, T den )
{
requires std::is_integral_v<T> {
return ( num + den - 1 ) / den;
}

Expand Down
15 changes: 7 additions & 8 deletions src/cata_variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ constexpr cata_variant_type type_for_impl( std::index_sequence<I...> )
{
constexpr size_t num_types = static_cast<size_t>( cata_variant_type::num_types );
constexpr std::array<bool, num_types> matches = {{
std::is_same<T, typename convert<static_cast<cata_variant_type>( I )>::type>::value...
std::is_same_v<T, typename convert<static_cast<cata_variant_type>( I )>::type>...
}
};
for( size_t i = 0; i < num_types; ++i ) {
Expand All @@ -112,7 +112,7 @@ constexpr cata_variant_type type_for_impl( std::index_sequence<I...> )
template<typename T>
struct convert_string {
using type = T;
static_assert( std::is_same<T, std::string>::value,
static_assert( std::is_same_v<T, std::string>,
"Intended for use only with string typedefs" );
static std::string to_string( const T &v ) {
return v;
Expand Down Expand Up @@ -355,10 +355,9 @@ class cata_variant

// Constructor that attempts to infer the type from the type of the
// value passed.
template < typename Value,
typename = std::enable_if_t <(
cata_variant_type_for<Value>() < cata_variant_type::num_types )>>
explicit cata_variant( Value && value ) {
template < typename Value>
explicit cata_variant( Value &&value ) requires(
cata_variant_type_for<Value>() < cata_variant_type::num_types ) {
constexpr cata_variant_type Type = cata_variant_type_for<Value>();
type_ = Type;
value_ =
Expand All @@ -372,8 +371,8 @@ class cata_variant
template<cata_variant_type Type, typename Value>
static cata_variant make( Value &&value ) {
return cata_variant(
Type, cata_variant_detail::convert<Type>::to_string(
std::forward<Value>( value ) ) );
Type, cata_variant_detail::convert<Type>::to_string(
std::forward<Value>( value ) ) );
}

// Call this to construct from a type + string. This should rarely be
Expand Down
4 changes: 2 additions & 2 deletions src/catalua_luna.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ struct luna_traits {
extern std::string_view current_comment;

template<typename T>
using remove_cv_ref_t = typename std::remove_cv<typename std::remove_reference<T>::type>::type;
using remove_cv_ref_t = std::remove_cv_t<std::remove_reference_t<T>>;

template<typename Signature>
using fx_traits = sol::meta::meta_detail::fx_traits<Signature>;
Expand All @@ -107,7 +107,7 @@ std::string doc_value_impl()
if constexpr( luna_traits<Val>::impl ) {
return std::string( luna_traits<Val>::name );
} else {
using ValNoPtr = typename std::remove_pointer<Val>::type;
using ValNoPtr = std::remove_pointer_t<Val>;
using ValBare = remove_cv_ref_t<ValNoPtr>;
if constexpr( luna_traits<ValBare>::impl ) {
return std::string( luna_traits<ValBare>::name );
Expand Down
12 changes: 4 additions & 8 deletions src/coordinates.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,11 @@ constexpr inline auto operator+(
return coord_point<PointResult, OriginL, Scale>( l.raw() + r.raw() );
}

template < typename PointL, typename PointR, origin OriginR, scale Scale,
// enable_if to prevent ambiguity with above when both args are
// relative
typename = std::enable_if_t < OriginR != origin::relative >>
template < typename PointL, typename PointR, origin OriginR, scale Scale>
constexpr inline auto operator+(
const coord_point<PointL, origin::relative, Scale> &l,
const coord_point<PointR, OriginR, Scale> &r )
requires( OriginR != origin::relative )
{
using PointResult = decltype( PointL() + PointR() );
return coord_point<PointResult, OriginR, Scale>( l.raw() + r.raw() );
Expand All @@ -248,13 +246,11 @@ constexpr inline auto operator-(
return coord_point<PointResult, OriginL, Scale>( l.raw() - r.raw() );
}

template < typename PointL, typename PointR, origin Origin, scale Scale,
// enable_if to prevent ambiguity with above when both args are
// relative
typename = std::enable_if_t < Origin != origin::relative >>
template < typename PointL, typename PointR, origin Origin, scale Scale>
constexpr inline auto operator-(
const coord_point<PointL, Origin, Scale> &l,
const coord_point<PointR, Origin, Scale> &r )
requires( Origin != origin::relative )
{
using PointResult = decltype( PointL() + PointR() );
return coord_point<PointResult, origin::relative, Scale>( l.raw() - r.raw() );
Expand Down
4 changes: 2 additions & 2 deletions src/dialogue.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ enum dialogue_consequence : unsigned char {
action
};

using talkfunction_ptr = std::add_pointer<void ( npc & )>::type;
using dialogue_fun_ptr = std::add_pointer<void( npc & )>::type;
using talkfunction_ptr = std::add_pointer_t<void ( npc & )>;
using dialogue_fun_ptr = std::add_pointer_t<void( npc & )>;

using trial_mod = std::pair<std::string, int>;

Expand Down
4 changes: 2 additions & 2 deletions src/enum_bitset.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
template<typename E>
class enum_bitset
{
static_assert( std::is_enum<E>::value, "the template argument is not an enum." );
static_assert( std::is_enum_v<E>, "the template argument is not an enum." );
static_assert( has_enum_traits<E>::value,
"a specialization of 'enum_traits<E>' template containing 'last' element of the enum must be defined somewhere. "
"The `last` constant must be of the same type as the enum iteslf."
Expand Down Expand Up @@ -89,7 +89,7 @@ class enum_bitset

private:
static constexpr size_t get_pos( E e ) noexcept {
return static_cast<size_t>( static_cast<typename std::underlying_type<E>::type>( e ) );
return static_cast<size_t>( static_cast<std::underlying_type_t<E>>( e ) );
}

std::bitset<enum_bitset<E>::size()> bits;
Expand Down
2 changes: 1 addition & 1 deletion src/enum_conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ std::string enum_to_string( E );
template<typename E>
std::unordered_map<std::string, E> build_enum_lookup_map()
{
static_assert( std::is_enum<E>::value, "E should be an enum type" );
static_assert( std::is_enum_v<E>, "E should be an enum type" );
static_assert( has_enum_traits<E>::value, "enum E needs a specialization of enum_traits" );
std::unordered_map<std::string, E> result;

Expand Down
2 changes: 1 addition & 1 deletion src/enum_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace enum_traits_detail
{

template<typename E>
using last_type = typename std::decay<decltype( enum_traits<E>::last )>::type;
using last_type = std::decay_t<decltype( enum_traits<E>::last )>;

} // namespace enum_traits_detail

Expand Down
2 changes: 1 addition & 1 deletion src/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ class event
using Spec = event_detail::event_spec<Type>;
// Using is_empty mostly just to verify that the type is defined at
// all, but it so happens that it ought to be empty too.
static_assert( std::is_empty<Spec>::value,
static_assert( std::is_empty_v<Spec>,
"spec for this event type must be defined and empty" );
static_assert( sizeof...( Args ) == Spec::fields.size(),
"wrong number of arguments for event type" );
Expand Down
41 changes: 22 additions & 19 deletions src/fmtlib_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,16 @@ FMT_BEGIN_NAMESPACE

// Implementations of enable_if_t and other metafunctions for older systems.
template <bool B, class T = void>
using enable_if_t = typename std::enable_if<B, T>::type;
using enable_if_t = std::enable_if_t<B, T>;
template <bool B, class T, class F>
using conditional_t = typename std::conditional<B, T, F>::type;
using conditional_t = std::conditional_t<B, T, F>;
template <bool B> using bool_constant = std::integral_constant<bool, B>;
template <typename T>
using remove_reference_t = typename std::remove_reference<T>::type;
using remove_reference_t = std::remove_reference_t<T>;
template <typename T>
using remove_const_t = typename std::remove_const<T>::type;
using remove_const_t = std::remove_const_t<T>;
template <typename T>
using remove_cvref_t = typename std::remove_cv<remove_reference_t<T>>::type;
using remove_cvref_t = std::remove_cv_t<remove_reference_t<T>>;
template <typename T> struct type_identity {
using type = T;
};
Expand Down Expand Up @@ -329,10 +329,10 @@ struct uint128_t {};

// Casts a nonnegative integer to unsigned.
template <typename Int>
FMT_CONSTEXPR typename std::make_unsigned<Int>::type to_unsigned( Int value )
FMT_CONSTEXPR std::make_unsigned_t<Int>to_unsigned( Int value )
{
FMT_ASSERT( value >= 0, "negative value" );
return static_cast<typename std::make_unsigned<Int>::type>( value );
return static_cast<std::make_unsigned_t<Int>>( value );
}

FMT_SUPPRESS_MSC_WARNING( 4566 ) constexpr unsigned char micro[] = "\u00B5";
Expand Down Expand Up @@ -1376,8 +1376,8 @@ template <typename Context> struct arg_mapper {
!has_fallback_formatter<T, Context>::value ) >
FMT_CONSTEXPR auto map( const T &val )
-> decltype( std::declval<arg_mapper>().map(
static_cast<typename std::underlying_type<T>::type>( val ) ) ) {
return map( static_cast<typename std::underlying_type<T>::type>( val ) );
static_cast<std::underlying_type_t<T>>( val ) ) ) {
return map( static_cast<std::underlying_type_t<T>>( val ) );
}
template < typename T,
FMT_ENABLE_IF( !is_string<T>::value
Expand Down Expand Up @@ -1839,8 +1839,8 @@ inline auto make_args_checked( const S &format_str,
{
static_assert(
detail::count < (
std::is_base_of<detail::view, remove_reference_t<Args>>::value &&
std::is_reference<Args>::value )... > () == 0,
std::is_base_of_v<detail::view, remove_reference_t<Args>> &&
std::is_reference_v<Args> )... > () == 0,
"passing views as lvalues is disallowed" );
detail::check_format_string<Args...>( format_str );
return {args...};
Expand Down Expand Up @@ -1889,8 +1889,8 @@ class dynamic_format_arg_store

enum {
value = !( detail::is_reference_wrapper<T>::value ||
std::is_same<T, basic_string_view<char_type>>::value ||
std::is_same<T, detail::std_string_view<char_type>>::value ||
std::is_same_v<T, basic_string_view<char_type>> ||
std::is_same_v<T, detail::std_string_view<char_type>> ||
( mapped_type != detail::type::cstring_type &&
mapped_type != detail::type::string_type &&
mapped_type != detail::type::custom_type ) )
Expand Down Expand Up @@ -1993,7 +1993,7 @@ class dynamic_format_arg_store
*/
template <typename T> void push_back( std::reference_wrapper<T> arg ) {
static_assert(
detail::is_named_arg<typename std::remove_cv<T>::type>::value ||
detail::is_named_arg<std::remove_cv_t<T>>::value ||
need_copy<T>::value,
"objects of built-in types and string views are always copied" );
emplace_arg( arg.get() );
Expand Down Expand Up @@ -2185,7 +2185,7 @@ struct wformat_args : basic_format_args<wformat_context> {
namespace detail
{

template < typename Char, FMT_ENABLE_IF( !std::is_same<Char, char>::value ) >
template < typename Char, FMT_ENABLE_IF( !std::is_same_v<Char, char> ) >
std::basic_string<Char> vformat(
basic_string_view<Char> format_str,
basic_format_args<buffer_context<type_identity_t<Char>>> args );
Expand All @@ -2199,7 +2199,7 @@ void vformat_to(
detail::locale_ref loc = {} );

template < typename Char, typename Args,
FMT_ENABLE_IF( !std::is_same<Char, char>::value ) >
FMT_ENABLE_IF( !std::is_same_v<Char, char> ) >
inline void vprint_mojibake( std::FILE *, basic_string_view<Char>, const Args & ) {}

FMT_API void vprint_mojibake( std::FILE *, string_view, format_args );
Expand All @@ -2215,7 +2215,8 @@ template <typename OutputIt, typename S, typename Char = char_t<S>,
bool enable = detail::is_output_iterator<OutputIt, Char>::value>
auto vformat_to( OutputIt out, const S &format_str,
basic_format_args<buffer_context<type_identity_t<Char>>> args )
-> typename std::enable_if<enable, OutputIt>::type
-> OutputIt
requires( enable )
{
decltype( detail::get_buffer<Char>( out ) ) buf( detail::get_buffer_init( out ) );
detail::vformat_to( buf, to_string_view( format_str ), args );
Expand All @@ -2237,7 +2238,8 @@ auto vformat_to( OutputIt out, const S &format_str,
template <typename OutputIt, typename S, typename... Args,
bool enable = detail::is_output_iterator<OutputIt, char_t<S>>::value>
inline auto format_to( OutputIt out, const S &format_str, Args && ... args ) ->
typename std::enable_if<enable, OutputIt>::type
OutputIt
requires( enable )
{
const auto &vargs = fmt::make_args_checked<Args...>( format_str, args... );
return vformat_to( out, to_string_view( format_str ), vargs );
Expand Down Expand Up @@ -2273,7 +2275,8 @@ template <typename OutputIt, typename S, typename... Args,
bool enable = detail::is_output_iterator<OutputIt, char_t<S>>::value>
inline auto format_to_n( OutputIt out, size_t n, const S &format_str,
const Args &... args ) ->
typename std::enable_if<enable, format_to_n_result<OutputIt>>::type
format_to_n_result<OutputIt>
requires( enable )
{
const auto &vargs = fmt::make_args_checked<Args...>( format_str, args... );
return vformat_to_n( out, n, to_string_view( format_str ), vargs );
Expand Down
4 changes: 2 additions & 2 deletions src/fmtlib_format-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2647,7 +2647,7 @@ void fallback_format( Double d, int num_digits, bool binary32, buffer<char> &buf
template <typename T>
int format_float( T value, int precision, float_specs specs, buffer<char> &buf )
{
static_assert( !std::is_same<T, float>::value, "" );
static_assert( !std::is_same_v<T, float>, "" );
FMT_ASSERT( value >= 0, "value is negative" );

const bool fixed = specs.format == float_format::fixed;
Expand Down Expand Up @@ -2718,7 +2718,7 @@ int snprintf_float( T value, int precision, float_specs specs,
{
// Buffer capacity must be non-zero, otherwise MSVC's vsnprintf_s will fail.
FMT_ASSERT( buf.capacity() > buf.size(), "empty buffer" );
static_assert( !std::is_same<T, float>::value, "" );
static_assert( !std::is_same_v<T, float>, "" );

// Subtract 1 to account for the difference in precision since we use %e for
// both general and exponent format.
Expand Down
Loading
Loading