Skip to content

Commit

Permalink
Update copyright year to 2024 and refactor type traits for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
FredM67 committed Dec 26, 2024
1 parent c66eac4 commit 90f3d2f
Show file tree
Hide file tree
Showing 26 changed files with 220 additions and 201 deletions.
4 changes: 3 additions & 1 deletion Mk2_3phase_RFdatalog_temp/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
#pragma once

#include "type_traits/conditional.hpp"
#include "type_traits/decay.hpp"
#include "type_traits/enable_if.hpp"
#include "type_traits/function_traits.hpp"
#include "type_traits/integral_constant.hpp"
#include "type_traits/is_array.hpp"
#include "type_traits/is_base_of.hpp"
Expand All @@ -31,6 +33,6 @@
#include "type_traits/is_signed.hpp"
#include "type_traits/is_unsigned.hpp"
#include "type_traits/make_unsigned.hpp"
#include "type_traits/make_void.hpp"
#include "type_traits/remove_const.hpp"
#include "type_traits/remove_reference.hpp"
#include "type_traits/void_t.hpp"
17 changes: 10 additions & 7 deletions Mk2_3phase_RFdatalog_temp/type_traits/conditional.hpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2023, Benoit BLANCHON
// Copyright © 2014-2024, Benoit BLANCHON
// MIT License

#pragma once

template< bool Condition, class TrueType, class FalseType >
struct conditional
{
typedef TrueType type;
struct conditional {
using type = TrueType;
};

template< class TrueType, class FalseType >
struct conditional< false, TrueType, FalseType >
{
typedef FalseType type;
struct conditional<false, TrueType, FalseType> {
using type = FalseType;
};

template <bool Condition, class TrueType, class FalseType>
using conditional_t =
typename conditional<Condition, TrueType, FalseType>::type;

27 changes: 27 additions & 0 deletions Mk2_3phase_RFdatalog_temp/type_traits/decay.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// ArduinoJson - https://arduinojson.org

Check warning on line 1 in Mk2_3phase_RFdatalog_temp/type_traits/decay.hpp

View workflow job for this annotation

GitHub Actions / spellcheck

Cannot decode file using encoding "utf-8"
// Copyright © 2014-2024, Benoit BLANCHON
// MIT License

#pragma once

#include <stddef.h> // size_t

template <typename T>
struct decay {
using type = T;
};

template <typename T>
struct decay<T&> : decay<T> {};

template <typename T>
struct decay<T&&> : decay<T> {};

template <typename T>
struct decay<T[]> : decay<T*> {};

template <typename T, size_t N>
struct decay<T[N]> : decay<T*> {};

template <typename T>
using decay_t = typename decay<T>::type;
2 changes: 1 addition & 1 deletion Mk2_3phase_RFdatalog_temp/type_traits/declval.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2023, Benoit BLANCHON
// Copyright © 2014-2024, Benoit BLANCHON
// MIT License

#pragma once
Expand Down
15 changes: 6 additions & 9 deletions Mk2_3phase_RFdatalog_temp/type_traits/enable_if.hpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2023, Benoit BLANCHON
// Copyright © 2014-2024, Benoit BLANCHON
// MIT License

#pragma once

// A meta-function that return the type T if Condition is true.
template< bool Condition, typename T = void >
struct enable_if
{
};
struct enable_if {};

template< typename T >
struct enable_if< true, T >
{
typedef T type;
struct enable_if<true, T> {
using type = T;
};

template< bool B, class T = void >
using enable_if_t = typename enable_if< B, T >::type;
template <bool Condition, typename T = void >
using enable_if_t = typename enable_if< Condition, T >::type;
22 changes: 22 additions & 0 deletions Mk2_3phase_RFdatalog_temp/type_traits/function_traits.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// ArduinoJson - https://arduinojson.org

Check warning on line 1 in Mk2_3phase_RFdatalog_temp/type_traits/function_traits.hpp

View workflow job for this annotation

GitHub Actions / spellcheck

Cannot decode file using encoding "utf-8"
// Copyright © 2014-2024, Benoit BLANCHON
// MIT License

#pragma once

template <typename Sig>
struct function_traits;

template <typename ReturnType, typename Arg1>
struct function_traits<ReturnType (*)(Arg1)> {
using return_type = ReturnType;
using arg1_type = Arg1;
};

template <typename ReturnType, typename Arg1, typename Arg2>
struct function_traits<ReturnType (*)(Arg1, Arg2)> {
using return_type = ReturnType;
using arg1_type = Arg1;
using arg2_type = Arg2;
};

25 changes: 9 additions & 16 deletions Mk2_3phase_RFdatalog_temp/type_traits/integral_constant.hpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2023, Benoit BLANCHON
// Copyright © 2014-2024, Benoit BLANCHON
// MIT License

#pragma once

template< typename T, T v >
struct integral_constant
{
static constexpr T value = v;
using value_type = T;
using type = integral_constant; // using injected-class-name
constexpr operator value_type() const noexcept
{
return value;
}
constexpr value_type operator()() const noexcept
{
return value;
} // since c++14
struct integral_constant {
static const T value = v;
};

typedef integral_constant< bool, true > true_type;
typedef integral_constant< bool, false > false_type;
template <bool B>
using bool_constant = integral_constant<bool, B>;

using true_type = bool_constant<true>;
using false_type = bool_constant<false>;

22 changes: 8 additions & 14 deletions Mk2_3phase_RFdatalog_temp/type_traits/is_array.hpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2023, Benoit BLANCHON
// Copyright © 2014-2024, Benoit BLANCHON
// MIT License

#pragma once
#include <stddef.h>

// size_t
template< typename T >
struct is_array : false_type
{
};
#include <stddef.h> // size_t

template< typename T >
struct is_array< T[] > : true_type
{
};
template <typename T>
struct is_array : false_type {};

template <typename T>
struct is_array<T[]> : true_type {};

template< typename T, size_t N >
struct is_array< T[N] > : true_type
{
};
struct is_array<T[N]> : true_type {};
13 changes: 6 additions & 7 deletions Mk2_3phase_RFdatalog_temp/type_traits/is_base_of.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2023, Benoit BLANCHON
// Copyright © 2014-2024, Benoit BLANCHON
// MIT License

#pragma once
Expand All @@ -8,15 +8,14 @@
// A meta-function that returns true if Derived inherits from TBase is an
// integral type.
template< typename TBase, typename TDerived >
class is_base_of
{
class is_base_of {
protected: // <- to avoid GCC's "all member functions in class are private"
static int probe(const TBase*);
static char probe(...);

public:
static const bool value =
sizeof(probe(reinterpret_cast< typename remove_reference< TDerived >::type* >(
0)))
== sizeof(int);
};
sizeof(probe(reinterpret_cast<remove_reference_t<TDerived>*>(0))) ==
sizeof(int);
};

5 changes: 2 additions & 3 deletions Mk2_3phase_RFdatalog_temp/type_traits/is_class.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2023, Benoit BLANCHON
// Copyright © 2014-2024, Benoit BLANCHON
// MIT License

#pragma once

#include "declval.hpp"

template< typename T >
struct is_class
{
struct is_class {
protected: // <- to avoid GCC's "all member functions in class are private"
template< typename U >
static int probe(void (U::*)(void));
Expand Down
2 changes: 1 addition & 1 deletion Mk2_3phase_RFdatalog_temp/type_traits/is_const.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2023, Benoit BLANCHON
// Copyright © 2014-2024, Benoit BLANCHON
// MIT License

#pragma once
Expand Down
4 changes: 2 additions & 2 deletions Mk2_3phase_RFdatalog_temp/type_traits/is_convertible.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2023, Benoit BLANCHON
// Copyright © 2014-2024, Benoit BLANCHON
// MIT License

#pragma once
Expand All @@ -25,7 +25,7 @@ struct is_convertible
static int probe(To);
static char probe(...);

static From& from_;
static const From& from_;

public:
static const bool value = sizeof(probe(from_)) == sizeof(int);
Expand Down
11 changes: 6 additions & 5 deletions Mk2_3phase_RFdatalog_temp/type_traits/is_enum.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2023, Benoit BLANCHON
// Copyright © 2014-2024, Benoit BLANCHON
// MIT License

#pragma once
Expand All @@ -11,7 +11,8 @@
#include "is_same.hpp"

template< typename T >
struct is_enum
{
static const bool value = is_convertible< T, int >::value && !is_class< T >::value && !is_integral< T >::value && !is_floating_point< T >::value;
};
struct is_enum {
static const bool value = is_convertible<T, long long>::value &&
!is_class<T>::value && !is_integral<T>::value &&
!is_floating_point<T>::value;
};
11 changes: 5 additions & 6 deletions Mk2_3phase_RFdatalog_temp/type_traits/is_floating_point.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2023, Benoit BLANCHON
// Copyright © 2014-2024, Benoit BLANCHON
// MIT License

#pragma once
Expand All @@ -10,8 +10,7 @@

template< class T >
struct is_floating_point
: integral_constant<
bool, //
is_same< float, typename remove_cv< T >::type >::value || is_same< double, typename remove_cv< T >::type >::value >
{
};
: integral_constant<bool, //
is_same<float, remove_cv_t<T>>::value ||
is_same<double, remove_cv_t<T>>::value> {};

29 changes: 15 additions & 14 deletions Mk2_3phase_RFdatalog_temp/type_traits/is_integral.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2023, Benoit BLANCHON
// Copyright © 2014-2024, Benoit BLANCHON
// MIT License

#pragma once
Expand All @@ -11,16 +11,17 @@
// clang-format off
template <typename T>
struct is_integral : integral_constant<bool,
is_same<typename remove_cv<T>::type, signed char>::value ||
is_same<typename remove_cv<T>::type, unsigned char>::value ||
is_same<typename remove_cv<T>::type, signed short>::value ||
is_same<typename remove_cv<T>::type, unsigned short>::value ||
is_same<typename remove_cv<T>::type, signed int>::value ||
is_same<typename remove_cv<T>::type, unsigned int>::value ||
is_same<typename remove_cv<T>::type, signed long>::value ||
is_same<typename remove_cv<T>::type, unsigned long>::value ||
is_same<typename remove_cv<T>::type, signed long long>::value ||
is_same<typename remove_cv<T>::type, unsigned long long>::value ||
is_same<typename remove_cv<T>::type, char>::value ||
is_same<typename remove_cv<T>::type, bool>::value> {};
// clang-format on
is_same<remove_cv_t<T>, signed char>::value ||
is_same<remove_cv_t<T>, unsigned char>::value ||
is_same<remove_cv_t<T>, signed short>::value ||
is_same<remove_cv_t<T>, unsigned short>::value ||
is_same<remove_cv_t<T>, signed int>::value ||
is_same<remove_cv_t<T>, unsigned int>::value ||
is_same<remove_cv_t<T>, signed long>::value ||
is_same<remove_cv_t<T>, unsigned long>::value ||
is_same<remove_cv_t<T>, signed long long>::value ||
is_same<remove_cv_t<T>, unsigned long long>::value ||
is_same<remove_cv_t<T>, char>::value ||
is_same<remove_cv_t<T>, bool>::value> {};
// clang-format on

11 changes: 4 additions & 7 deletions Mk2_3phase_RFdatalog_temp/type_traits/is_pointer.hpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2023, Benoit BLANCHON
// Copyright © 2014-2024, Benoit BLANCHON
// MIT License

#pragma once

#include "integral_constant.hpp"

template< typename T >
struct is_pointer : false_type
{
};
struct is_pointer : false_type {};

template< typename T >
struct is_pointer< T* > : true_type
{
};
struct is_pointer<T*> : true_type {};

10 changes: 3 additions & 7 deletions Mk2_3phase_RFdatalog_temp/type_traits/is_same.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2023, Benoit BLANCHON
// Copyright © 2014-2024, Benoit BLANCHON
// MIT License

#pragma once
Expand All @@ -8,14 +8,10 @@

// A meta-function that returns true if types T and U are the same.
template< typename T, typename U >
struct is_same : false_type
{
};
struct is_same : false_type {};

template< typename T >
struct is_same< T, T > : true_type
{
};
struct is_same<T, T> : true_type {};

template< class T, class U >
inline constexpr bool is_same_v = is_same< T, U >::value;
Loading

0 comments on commit 90f3d2f

Please sign in to comment.