Skip to content

Commit

Permalink
Utility: add a forward declaration header for std::array as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
mosra committed Mar 27, 2019
1 parent 49e3dc7 commit fd8030d
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 6 deletions.
7 changes: 4 additions & 3 deletions doc/corrade-changelog.dox
Expand Up @@ -64,11 +64,12 @@ namespace Corrade {
copies.
- New @ref Utility::Directory::join(std::initializer_list<std::string>)
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 <cmath> @ce on C++17 an up
Expand Down
1 change: 1 addition & 0 deletions src/Corrade/Utility/CMakeLists.txt
Expand Up @@ -57,6 +57,7 @@ if(WITH_UTILITY)
Resource.h
Sha1.h
String.h
StlForwardArray.h
StlForwardString.h
StlForwardTuple.h
StlForwardVector.h
Expand Down
56 changes: 56 additions & 0 deletions 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š <mosra@centrum.cz>
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 <array> @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 <utility>
#else
/* Including the full definition otherwise. Couldn't find the declaration for
libstdc++ (std::tuple is defined in <type_traits> but std::array is not),
that however doesn't mean the forward declaration doesn't exist. */
#include <array>
#endif

#endif
3 changes: 2 additions & 1 deletion src/Corrade/Utility/StlForwardString.h
Expand Up @@ -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 <string> @ce.
@see @ref Corrade/Utility/StlForwardTuple.h,
@see @ref Corrade/Utility/StlForwardArray.h,
@ref Corrade/Utility/StlForwardTuple.h,
@ref Corrade/Utility/StlForwardVector.h
*/

Expand Down
3 changes: 2 additions & 1 deletion src/Corrade/Utility/StlForwardTuple.h
Expand Up @@ -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 <tuple> @ce.
@see @ref Corrade/Utility/StlForwardString.h,
@see @ref Corrade/Utility/StlForwardArray.h,
@ref Corrade/Utility/StlForwardString.h,
@ref Corrade/Utility/StlForwardVector.h
*/

Expand Down
3 changes: 2 additions & 1 deletion src/Corrade/Utility/StlForwardVector.h
Expand Up @@ -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 <vector> @ce.
@see @ref Corrade/Utility/StlForwardString.h,
@see @ref Corrade/Utility/StlForwardArray.h,
@ref Corrade/Utility/StlForwardString.h,
@ref Corrade/Utility/StlForwardTuple.h
*/

Expand Down
1 change: 1 addition & 0 deletions src/Corrade/Utility/Test/CMakeLists.txt
Expand Up @@ -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)
Expand Down
49 changes: 49 additions & 0 deletions 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š <mosra@centrum.cz>
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 <array> */
#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<int, 3>* a = nullptr;
CORRADE_VERIFY(!a);
}

}}}}

CORRADE_TEST_MAIN(Corrade::Utility::Test::StlForwardArrayTest)

0 comments on commit fd8030d

Please sign in to comment.