mirror of
https://github.com/libSDL2pp/libSDL2pp.git
synced 2025-08-04 03:15:59 -04:00
Added Private/Utility.hh with Or for template metaprogramming
This commit is contained in:
parent
7cfc30970b
commit
8489103f6a
@ -158,6 +158,7 @@ SET(LIBRARY_HEADERS
|
||||
SDL2pp/Texture.hh
|
||||
SDL2pp/Wav.hh
|
||||
SDL2pp/Window.hh
|
||||
SDL2pp/Private/Utility.hh
|
||||
)
|
||||
|
||||
SET(LIBRARY_EXTERNAL_HEADERS
|
||||
|
@ -21,7 +21,8 @@ INPUT = "@CMAKE_CURRENT_SOURCE_DIR@/SDL2pp" \
|
||||
RECURSIVE = YES
|
||||
|
||||
# Exclude foreign files
|
||||
EXCLUDE = "@CMAKE_CURRENT_SOURCE_DIR@/SDL2pp/external"
|
||||
EXCLUDE = "@CMAKE_CURRENT_SOURCE_DIR@/SDL2pp/external" \
|
||||
"@CMAKE_CURRENT_SOURCE_DIR@/SDL2pp/Private"
|
||||
|
||||
# Examples (doesn't work atm)
|
||||
EXAMPLE_PATH = "@CMAKE_CURRENT_SOURCE_DIR@/examples"
|
||||
|
70
SDL2pp/Private/Utility.hh
Normal file
70
SDL2pp/Private/Utility.hh
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
libSDL2pp - C++11 bindings/wrapper for SDL2
|
||||
Copyright (C) 2017 Vraiment <jemc44@gmail.com>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef SDL2PP_PRIVATE_UTILITY_HH
|
||||
#define SDL2PP_PRIVATE_UTILITY_HH
|
||||
|
||||
#if __cplusplus > 201703L
|
||||
// No need to include utility, until C++17 there
|
||||
// is no definition for std::disjuntion before
|
||||
#include <utility>
|
||||
#endif
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
|
||||
namespace SDL2pp {
|
||||
/*
|
||||
* This is code not to be used directly by users of SDL2pp.
|
||||
*/
|
||||
namespace Private {
|
||||
/*
|
||||
* Templated class to perform an "OR" operation on any amount of types.
|
||||
*
|
||||
* Usage is as follows:
|
||||
* template <typename T,
|
||||
* typename = typename Or<HasFeatureOne<T>, HasFeatureTwo<T>>
|
||||
* void UseFeatureOneOrFeatureTwo(T t) {
|
||||
* // The code will be only compiled if either
|
||||
* // HasFeatureOne<T> or HasFeatureTwo<T> are type_true
|
||||
* }
|
||||
*/
|
||||
#if __cplusplus >= 201703L
|
||||
// Use the standard definitions if they are available
|
||||
template <typename T, typename... Tx>
|
||||
using Or = typename std::disjunction<T, Tx...>::type;
|
||||
#else
|
||||
template <typename...>
|
||||
struct OrOperation : std::false_type { };
|
||||
|
||||
template <typename T>
|
||||
struct OrOperation<T> : T { };
|
||||
|
||||
template <typename T, typename... Tx>
|
||||
struct OrOperation<T, Tx...> : std::conditional<bool(T::value), T, OrOperation<Tx...>> { };
|
||||
|
||||
template <typename T, typename... Tx>
|
||||
using Or = typename OrOperation<T, Tx...>::type;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user