From 8489103f6a13a573c14ea3bd5dcf4a966b20aa36 Mon Sep 17 00:00:00 2001 From: Vraiment Date: Sun, 30 Jul 2017 12:03:57 -0700 Subject: [PATCH] Added Private/Utility.hh with Or for template metaprogramming --- CMakeLists.txt | 1 + Doxyfile.in | 3 +- SDL2pp/Private/Utility.hh | 70 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 SDL2pp/Private/Utility.hh diff --git a/CMakeLists.txt b/CMakeLists.txt index 51eb91e..b31df9a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -158,6 +158,7 @@ SET(LIBRARY_HEADERS SDL2pp/Texture.hh SDL2pp/Wav.hh SDL2pp/Window.hh + SDL2pp/Private/Utility.hh ) SET(LIBRARY_EXTERNAL_HEADERS diff --git a/Doxyfile.in b/Doxyfile.in index 54617af..02d3b47 100644 --- a/Doxyfile.in +++ b/Doxyfile.in @@ -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" diff --git a/SDL2pp/Private/Utility.hh b/SDL2pp/Private/Utility.hh new file mode 100644 index 0000000..e0fb6df --- /dev/null +++ b/SDL2pp/Private/Utility.hh @@ -0,0 +1,70 @@ +/* + libSDL2pp - C++11 bindings/wrapper for SDL2 + Copyright (C) 2017 Vraiment + + 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 +#endif + +#include + + +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 , HasFeatureTwo> + * void UseFeatureOneOrFeatureTwo(T t) { + * // The code will be only compiled if either + * // HasFeatureOne or HasFeatureTwo are type_true + * } + */ +#if __cplusplus >= 201703L + // Use the standard definitions if they are available + template + using Or = typename std::disjunction::type; +#else + template + struct OrOperation : std::false_type { }; + + template + struct OrOperation : T { }; + + template + struct OrOperation : std::conditional> { }; + + template + using Or = typename OrOperation::type; +#endif +} +} + +#endif