diff options
author | peterbell10 <peterbell10@live.co.uk> | 2017-05-22 22:27:55 +0200 |
---|---|---|
committer | Lukas Pioch <lukas@zgow.de> | 2017-05-22 22:27:55 +0200 |
commit | 8a890cf945cfbd72f6e4b64f8c7b52d2c6ca099e (patch) | |
tree | d29525d02edb691c25e930b0d795d0dba160a34c /src/BlockID.h | |
parent | Spawn eggs works again (diff) | |
download | cuberite-8a890cf945cfbd72f6e4b64f8c7b52d2c6ca099e.tar cuberite-8a890cf945cfbd72f6e4b64f8c7b52d2c6ca099e.tar.gz cuberite-8a890cf945cfbd72f6e4b64f8c7b52d2c6ca099e.tar.bz2 cuberite-8a890cf945cfbd72f6e4b64f8c7b52d2c6ca099e.tar.lz cuberite-8a890cf945cfbd72f6e4b64f8c7b52d2c6ca099e.tar.xz cuberite-8a890cf945cfbd72f6e4b64f8c7b52d2c6ca099e.tar.zst cuberite-8a890cf945cfbd72f6e4b64f8c7b52d2c6ca099e.zip |
Diffstat (limited to '')
-rw-r--r-- | src/BlockID.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/BlockID.h b/src/BlockID.h index 8ce7a040b..bd24f9312 100644 --- a/src/BlockID.h +++ b/src/BlockID.h @@ -1212,3 +1212,31 @@ extern cItem GetIniItemSet(cIniFile & a_IniFile, const char * a_Section, const c +/** Base case for IsOneOf to handle empty template aguments. */ +template <class = void> +bool IsOneOf(BLOCKTYPE a_BlockType) +{ + return false; +} + + +/** Returns true if a_BlockType is equal to any of the variadic template arguments. +Some example usage: +\code + IsOneOf<>(E_BLOCK_AIR) == false + IsOneOf<E_BLOCK_AIR>(E_BLOCK_DIRT) == false + IsOneOf<E_BLOCK_AIR, E_BLOCK_DIRT>(E_BLOCK_DIRT) == true +\endcode +The implementation is ugly but it is equivalent to this C++17 fold expression: +\code + ((a_BlockType == Types) || ...) +\endcode +Just written to be valid without fold expressions or SFINAE. */ +template <BLOCKTYPE Head, BLOCKTYPE ... Tail> +bool IsOneOf(BLOCKTYPE a_BlockType) +{ + return ((a_BlockType == Head) || (IsOneOf<Tail...>(a_BlockType))); +} + + + |