diff --git a/doc/corrade-changelog.dox b/doc/corrade-changelog.dox index aa1e97318..5365d0442 100644 --- a/doc/corrade-changelog.dox +++ b/doc/corrade-changelog.dox @@ -64,11 +64,12 @@ namespace Corrade { copies. - New @ref Utility::Directory::join(std::initializer_list) overload for joining a path from multiple parts at once -- New @ref Corrade/Utility/StlForwardString.h, +- New @ref Corrade/Utility/StlForwardArray.h, + @ref Corrade/Utility/StlForwardString.h, @ref Corrade/Utility/StlForwardTuple.h and @ref Corrade/Utility/StlForwardVector.h headers providing lightweight - forward declarations for @ref std::string, @ref std::tuple and - @ref std::vector on platforms that have them (and including the full + forward declarations for @ref std::array, @ref std::string, @ref std::tuple + and @ref std::vector on platforms that have them (and including the full definition otherwise) - New @ref Corrade/Utility/StlMath.h header providing bloat-free @cpp #include @ce on C++17 an up diff --git a/src/Corrade/Utility/CMakeLists.txt b/src/Corrade/Utility/CMakeLists.txt index 1f53f31ae..985df0c75 100644 --- a/src/Corrade/Utility/CMakeLists.txt +++ b/src/Corrade/Utility/CMakeLists.txt @@ -57,6 +57,7 @@ if(WITH_UTILITY) Resource.h Sha1.h String.h + StlForwardArray.h StlForwardString.h StlForwardTuple.h StlForwardVector.h diff --git a/src/Corrade/Utility/StlForwardArray.h b/src/Corrade/Utility/StlForwardArray.h new file mode 100644 index 000000000..9c5312357 --- /dev/null +++ b/src/Corrade/Utility/StlForwardArray.h @@ -0,0 +1,56 @@ +#ifndef Corrade_Utility_StlForwardArray_h +#define Corrade_Utility_StlForwardArray_h +/* + This file is part of Corrade. + + Copyright © 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, + 2017, 2018, 2019 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +/** @file +@brief Forward declaration for @ref std::array + +On @ref CORRADE_TARGET_LIBCXX "libc++" and +@ref CORRADE_TARGET_DINKUMWARE "MSVC STL" includes a lightweight +implementation-specific STL header containing just the forward declaration of +@ref std::array. On other implementations where forward declaration is not +possible or is unknown is equivalent to @cpp #include @ce. +@see @ref Corrade/Utility/StlForwardString.h, + @ref Corrade/Utility/StlForwardTuple.h, + @ref Corrade/Utility/StlForwardVector.h +*/ + +#include "Corrade/configure.h" + +#ifdef CORRADE_TARGET_LIBCXX +/* https://github.com/llvm-mirror/libcxx/blob/73d2eccc78ac83d5947243c4d26a53f668b4f432/include/__tuple#L223 */ +#include <__tuple> +#elif defined(CORRADE_TARGET_DINKUMWARE) +/* MSVC has it defined next to std::pair */ +#include +#else +/* Including the full definition otherwise. Couldn't find the declaration for + libstdc++ (std::tuple is defined in but std::array is not), + that however doesn't mean the forward declaration doesn't exist. */ +#include +#endif + +#endif diff --git a/src/Corrade/Utility/StlForwardString.h b/src/Corrade/Utility/StlForwardString.h index 523c31d50..ed8e2856e 100644 --- a/src/Corrade/Utility/StlForwardString.h +++ b/src/Corrade/Utility/StlForwardString.h @@ -34,7 +34,8 @@ implementation-specific STL header containing just the forward declaration of @ref std::string. On @ref CORRADE_TARGET_DINKUMWARE "MSVC STL" and other implementations where forward declaration is not possible or is unknown is equivalent to @cpp #include @ce. -@see @ref Corrade/Utility/StlForwardTuple.h, +@see @ref Corrade/Utility/StlForwardArray.h, + @ref Corrade/Utility/StlForwardTuple.h, @ref Corrade/Utility/StlForwardVector.h */ diff --git a/src/Corrade/Utility/StlForwardTuple.h b/src/Corrade/Utility/StlForwardTuple.h index a021a6fd9..7e4eb3eac 100644 --- a/src/Corrade/Utility/StlForwardTuple.h +++ b/src/Corrade/Utility/StlForwardTuple.h @@ -33,7 +33,8 @@ and @ref CORRADE_TARGET_DINKUMWARE "MSVC STL" includes a lightweight implementation-specific STL header containing just the forward declaration of @ref std::tuple. On other implementations where forward declaration is unknown is equivalent to @cpp #include @ce. -@see @ref Corrade/Utility/StlForwardString.h, +@see @ref Corrade/Utility/StlForwardArray.h, + @ref Corrade/Utility/StlForwardString.h, @ref Corrade/Utility/StlForwardVector.h */ diff --git a/src/Corrade/Utility/StlForwardVector.h b/src/Corrade/Utility/StlForwardVector.h index 9bf7c9337..80b498bbb 100644 --- a/src/Corrade/Utility/StlForwardVector.h +++ b/src/Corrade/Utility/StlForwardVector.h @@ -34,7 +34,8 @@ implementation-specific STL header containing just the forward declaration of @ref std::vector. On @ref CORRADE_TARGET_DINKUMWARE "MSVC STL" and other implementations where forward declaration is not possible or is unknown is equivalent to @cpp #include @ce. -@see @ref Corrade/Utility/StlForwardString.h, +@see @ref Corrade/Utility/StlForwardArray.h, + @ref Corrade/Utility/StlForwardString.h, @ref Corrade/Utility/StlForwardTuple.h */ diff --git a/src/Corrade/Utility/Test/CMakeLists.txt b/src/Corrade/Utility/Test/CMakeLists.txt index 4ed0f3ec8..793fda18b 100644 --- a/src/Corrade/Utility/Test/CMakeLists.txt +++ b/src/Corrade/Utility/Test/CMakeLists.txt @@ -162,6 +162,7 @@ target_include_directories(UtilityFormatTest PRIVATE ${CMAKE_CURRENT_BINARY_DIR} corrade_add_test(UtilityHashDigestTest HashDigestTest.cpp) corrade_add_test(UtilityMacrosTest MacrosTest.cpp) corrade_add_test(UtilitySha1Test Sha1Test.cpp) +corrade_add_test(UtilityStlForwardArrayTest StlForwardArrayTest.cpp) corrade_add_test(UtilityStlForwardStringTest StlForwardStringTest.cpp) corrade_add_test(UtilityStlForwardTupleTest StlForwardTupleTest.cpp) corrade_add_test(UtilityStlForwardVectorTest StlForwardVectorTest.cpp) diff --git a/src/Corrade/Utility/Test/StlForwardArrayTest.cpp b/src/Corrade/Utility/Test/StlForwardArrayTest.cpp new file mode 100644 index 000000000..c3b7c481f --- /dev/null +++ b/src/Corrade/Utility/Test/StlForwardArrayTest.cpp @@ -0,0 +1,49 @@ +/* + This file is part of Corrade. + + Copyright © 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, + 2017, 2018, 2019 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include "Corrade/TestSuite/Tester.h" /* This doesn't include */ +#include "Corrade/Utility/StlForwardArray.h" + +namespace Corrade { namespace Utility { namespace Test { namespace { + +struct StlForwardArrayTest: TestSuite::Tester { + explicit StlForwardArrayTest(); + + void test(); +}; + +StlForwardArrayTest::StlForwardArrayTest() { + addTests({&StlForwardArrayTest::test}); +} + +void StlForwardArrayTest::test() { + /* Just verify that this compiles without error */ + std::array* a = nullptr; + CORRADE_VERIFY(!a); +} + +}}}} + +CORRADE_TEST_MAIN(Corrade::Utility::Test::StlForwardArrayTest)