Skip to content

Commit

Permalink
Move the initialization and creation tags to the root namespace.
Browse files Browse the repository at this point in the history
This was done for Magnum already and it's just a lot of unnecessary
typing. Given that the containers may eventually get moved there as
well, this makes sense.

Unfortunately to avoid the deprecation warnings I had to prefix all
current uses in the Containers library by Corrade::. Ugly, but temporary
only since the aliases get removed.
  • Loading branch information
mosra committed Apr 30, 2021
1 parent c5b5b9e commit c0267de
Show file tree
Hide file tree
Showing 47 changed files with 662 additions and 514 deletions.
10 changes: 5 additions & 5 deletions doc/corrade-changelog-old.dox
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ a high-level overview.
but with compile-time size information
- New @ref Containers::Optional class, providing a subset of functionality
from C++17 @ref std::optional (see [mosra/corrade#36](https://github.com/mosra/corrade/pull/36))
- Added @ref Containers::NoInit, @ref Containers::DirectInit,
@ref Containers::DefaultInit, @ref Containers::ValueInit and
@ref Containers::InPlaceInit tags for better control over initialization of
@ref Containers::Array and @ref Containers::StaticArray
- Added @cpp Containers::NoInit @ce, @cpp Containers::DirectInit @ce,
@cpp Containers::DefaultInit @ce, @cpp Containers::ValueInit @ce and
@cpp Containers::InPlaceInit @ce tags for better control over
initialization of @ref Containers::Array and @ref Containers::StaticArray
- Added @ref Containers::Array::Array(InPlaceInitT, std::initializer_list<T>)
to create @ref Containers::Array from an initializer list
- New @ref Containers::Array::Array(T*, std::size_t, D) "Containers::Array::Array(T*, std::size_t, D)"
Expand Down Expand Up @@ -264,7 +264,7 @@ a high-level overview.

@subsubsection corrade-changelog-2018-02-changes-containers Containers library

- @ref Containers::EnumSet now can take a @ref Containers::NoInit tag to
- @ref Containers::EnumSet now can take a @cpp Containers::NoInit @ce tag to
create an uninitialized value
- Exposed @ref Containers::EnumSet::FullValue constant

Expand Down
31 changes: 19 additions & 12 deletions doc/corrade-changelog.dox
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ namespace Corrade {
- New @ref Containers::Array2, @ref Containers::Array3 and
@ref Containers::Array4 convenience aliases for
@ref Containers::StaticArray, together with @ref Containers::Array1 that's
useful in case you want to take advantage of the @ref Containers::NoInit
tag on an arbitrary type and @ref Containers::Optional doesn't suit the use
case.
useful in case you want to take advantage of the @ref NoInit tag on an
arbitrary type and @ref Containers::Optional doesn't suit the use case.
- New @ref Containers::ArrayView2, @ref Containers::ArrayView3 and
@ref Containers::ArrayView4 convenience aliases for
@ref Containers::StaticArrayView
Expand Down Expand Up @@ -106,8 +105,8 @@ namespace Corrade {
- @ref Containers::Array::Array(InPlaceInitT, std::initializer_list<T>)
constructor is no longer @cpp explicit @ce to allow for easier use in
initializer lists
- @ref Containers::ScopeGuard now has a @ref Containers::NoCreate constructor
and is movable in order to support deferred creation
- @ref Containers::ScopeGuard now has a @ref NoCreate constructor and is
movable in order to support deferred creation
- @ref Containers::LinkedList destruction was changed in a way that makes
@ref Containers::LinkedListItem::list() still accessible in a destructor
of @ref Containers::LinkedListItem subclasses
Expand Down Expand Up @@ -241,6 +240,14 @@ namespace Corrade {
however you'll get a deprecation notice. Since the variable got saved to
CMake cache, to get rid of the message, you may need to either recreate
your build directory or explicitly delete it from the cache.
- The @cpp Corrade/Containers/Tags.h @ce header,
@cpp Containers::DefaultInit @ce, @cpp Containers::ValueInit @ce,
@cpp Containers::NoInit @ce, @cpp Containers::NoCreate @ce,
@cpp Containers::DirectInit @ce, @cpp Containers::InPlaceInit @ce and
related tag types were moved to @ref Corrade/Tags.h and the root
@ref Corrade namespace, available as @ref DefaultInit, @ref ValueInit,
@ref NoInit, @ref NoCreate, @ref DirectInit, @ref InPlaceInit and related
tag types

@subsection corrade-changelog-latest-compatibility Potential compatibility breakages, removed APIs

Expand Down Expand Up @@ -529,12 +536,12 @@ Released 2020-06-27, tagged as
compile when used with an empty argument list. The original functionality
is provided by @ref CORRADE_INTERNAL_ASSERT_UNREACHABLE() instead.
- @ref Containers::Array and @ref Containers::StaticArray was switched to
do the @ref Containers::ValueInit construction by default instead of
@ref Containers::DefaultInit, i.e. zero-initializing trivial types instead
of keeping them uninitialized. Apart from introducing potential slowdowns
due to the additional zero-ininitialization this isn't really breaking,
just makes the default safer; and you still have the option to choose a
different initialization.
do the @cpp Containers::ValueInit @ce construction by default instead of
@cpp Containers::DefaultInit @ce, i.e. zero-initializing trivial types
instead of keeping them uninitialized. Apart from introducing potential
slowdowns due to the additional zero-ininitialization this isn't really
breaking, just makes the default safer; and you still have the option to
choose a different initialization.
- @ref Utility::Debug and @ref Utility::format() now prints @cpp long double @ce
with 15 significant digits instead of 18 on platforms where it is 64-bit
instead of 80-bit
Expand Down Expand Up @@ -1002,7 +1009,7 @@ Released 2019-02-04, tagged as
@ref std::unique_ptr
- New @ref Containers::Reference class, a lightweight equivalent to
@ref std::reference_wrapper
- New @ref Containers::NoCreate tag for constructing instances
- New @cpp Containers::NoCreate @ce tag for constructing instances
equivalent to a moved-from state. This tag was used in Magnum already,
moving it here to make it available to a wider set of APIs.
- New @ref Containers::optional(Args&&... args) overload for in-place
Expand Down
6 changes: 3 additions & 3 deletions doc/namespaces.dox
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
@brief Root namespace

THe root namespace alone doesn't contain any functionality except for the
@ref Corrade/Corrade.h header, see subnamespaces for more information. To use
the base from CMake, request the `Corrade` package and link to the
`Corrade::Corrade` target:
@ref Corrade/Corrade.h and @ref Corrade/Tags.h headers, see subnamespaces for
more information. To use the base from CMake, request the `Corrade` package and
link to the `Corrade::Corrade` target:

@code{.cmake}
find_package(Corrade REQUIRED)
Expand Down
34 changes: 17 additions & 17 deletions doc/snippets/Containers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,20 +230,20 @@ c[3] = 25; // c == {3, 18, -157, 25}
/* [Array-usage-initialization] */
/* These two are equivalent */
Containers::Array<int> a1{5};
Containers::Array<int> a2{Containers::ValueInit, 5};
Containers::Array<int> a2{ValueInit, 5};

/* Array of 100 integers, uninitialized */
Containers::Array<int> b{Containers::NoInit, 100};
Containers::Array<int> b{NoInit, 100};

/* Array of a type with no default constructor. All five elements will be
initialized to {5.2f, 0.5f, 1.0f}. */
struct Vec3 {
explicit Vec3(float, float, float) {}
};
Containers::Array<Vec3> c{Containers::DirectInit, 5, 5.2f, 0.4f, 1.0f};
Containers::Array<Vec3> c{DirectInit, 5, 5.2f, 0.4f, 1.0f};

/* Array from an initializer list. These two are equivalent. */
Containers::Array<int> d1{Containers::InPlaceInit, {1, 2, 3, 4, -5, 0, 42}};
Containers::Array<int> d1{InPlaceInit, {1, 2, 3, 4, -5, 0, 42}};
auto d2 = Containers::array<int>({1, 2, 3, 4, -5, 0, 42});
/* [Array-usage-initialization] */
}
Expand Down Expand Up @@ -321,7 +321,7 @@ struct Foo {
explicit Foo(int) {}
};

Containers::Array<Foo> e{Containers::NoInit, 5};
Containers::Array<Foo> e{NoInit, 5};

int index = 0;
for(Foo& f: e) new(&f) Foo{index++};
Expand Down Expand Up @@ -539,8 +539,8 @@ static_cast<void>(info);
Containers::ArrayView<std::string> strings;
Containers::ArrayView<Containers::Reference<std::string>> references;
Containers::ArrayTuple data{
{Containers::ValueInit, 15, strings},
{Containers::NoInit, 15, references}
{ValueInit, 15, strings},
{NoInit, 15, references}
};

/* Initialize all references to point to the strings */
Expand All @@ -555,8 +555,8 @@ for(std::size_t i = 0; i != strings.size(); ++i)
Containers::ArrayView<std::uint64_t> latencies;
Containers::ArrayView<float> averages;
Containers::ArrayTuple data{
{{Containers::NoInit, 200*1024*1024, latencies},
{Containers::NoInit, 200*1024*1024, averages}},
{{NoInit, 200*1024*1024, latencies},
{NoInit, 200*1024*1024, averages}},
[](std::size_t size, std::size_t)
-> std::pair<char*, Utility::Directory::MapDeleter>
{
Expand Down Expand Up @@ -733,7 +733,7 @@ auto b = Containers::optional(value);

{
/* [optional-inplace] */
auto a = Containers::Optional<std::string>{Containers::InPlaceInit, 'a', 'b'};
auto a = Containers::Optional<std::string>{InPlaceInit, 'a', 'b'};
auto b = Containers::optional<std::string>('a', 'b');
/* [optional-inplace] */
}
Expand All @@ -749,7 +749,7 @@ auto b = Containers::optional<std::string>('a', 'b');
{
Containers::StringView filename;
/* [ScopeGuard-deferred] */
Containers::ScopeGuard e{Containers::NoCreate};
Containers::ScopeGuard e{NoCreate};

/* Read from stdin if desired, otherwise scope-guard an opened file */
int fd;
Expand Down Expand Up @@ -815,21 +815,21 @@ c[3] = 25; // c == {3, 18, -157, 25}
/* [StaticArray-usage-initialization] */
/* These two are equivalent */
Containers::StaticArray<5, int> a1;
Containers::StaticArray<5, int> a2{Containers::DefaultInit};
Containers::StaticArray<5, int> a2{DefaultInit};

/* Array of 100 integers, uninitialized */
Containers::StaticArray<100, int> b{Containers::NoInit};
Containers::StaticArray<100, int> b{NoInit};

/* Array of 4 values initialized in-place. These two are equivalent. */
Containers::StaticArray<4, int> c1{3, 18, -157, 0};
Containers::StaticArray<4, int> c2{Containers::InPlaceInit, 3, 18, -157, 0};
Containers::StaticArray<4, int> c2{InPlaceInit, 3, 18, -157, 0};

/* Array of a type with no default constructor. All five elements will be
initialized to {5.2f, 0.5f, 1.0f}. */
struct Vec3 {
explicit Vec3(float, float, float) {}
};
Containers::StaticArray<5, Vec3> d{Containers::DirectInit, 5.2f, 0.4f, 1.0f};
Containers::StaticArray<5, Vec3> d{DirectInit, 5.2f, 0.4f, 1.0f};
/* [StaticArray-usage-initialization] */
}

Expand All @@ -839,7 +839,7 @@ struct Foo {
explicit Foo(int) {}
};

Containers::StaticArray<5, Foo> e{Containers::NoInit};
Containers::StaticArray<5, Foo> e{NoInit};

int index = 0;
for(Foo& f: e) new(&f) Foo{index++};
Expand Down Expand Up @@ -1076,7 +1076,7 @@ auto b = Containers::pointer(ptr);

{
/* [pointer-inplace] */
auto a = Containers::Pointer<std::string>{Containers::InPlaceInit, 'a', 'b'};
auto a = Containers::Pointer<std::string>{InPlaceInit, 'a', 'b'};
auto b = Containers::pointer<std::string>('a', 'b');
/* [pointer-inplace] */
}
Expand Down
3 changes: 2 additions & 1 deletion src/Corrade/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/version.h.cmake
${CMAKE_CURRENT_BINARY_DIR}/version.h)

set(Corrade_HEADERS
Corrade.h)
Corrade.h
Tags.h)

# Force IDEs to display all header files in project view
add_custom_target(Corrade SOURCES ${Corrade_HEADERS})
Expand Down
21 changes: 10 additions & 11 deletions src/Corrade/Containers/Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@
#include <type_traits>
#include <utility>

#include "Corrade/configure.h"
#include "Corrade/Tags.h"
#include "Corrade/Containers/ArrayView.h"
#include "Corrade/Containers/Tags.h"
#include "Corrade/Containers/constructHelpers.h"

namespace Corrade { namespace Containers {
Expand Down Expand Up @@ -334,7 +333,7 @@ class Array {
* @ref Array(NoInitT, std::size_t) variant instead.
* @see @ref DefaultInit, @ref std::is_trivial
*/
explicit Array(DefaultInitT, std::size_t size): _data{size ? new T[size] : nullptr}, _size{size}, _deleter{nullptr} {}
explicit Array(Corrade::DefaultInitT, std::size_t size): _data{size ? new T[size] : nullptr}, _size{size}, _deleter{nullptr} {}

/**
* @brief Construct a value-initialized array
Expand All @@ -345,7 +344,7 @@ class Array {
* is zero, no allocation is done.
* @see @ref ValueInit, @ref Array(DefaultInitT, std::size_t)
*/
explicit Array(ValueInitT, std::size_t size): _data{size ? new T[size]() : nullptr}, _size{size}, _deleter{nullptr} {}
explicit Array(Corrade::ValueInitT, std::size_t size): _data{size ? new T[size]() : nullptr}, _size{size}, _deleter{nullptr} {}

/**
* @brief Construct an array without initializing its contents
Expand Down Expand Up @@ -373,7 +372,7 @@ class Array {
* @ref array(std::initializer_list<T>), @ref deleter(),
* @ref std::is_trivial
*/
explicit Array(NoInitT, std::size_t size): _data{size ? Implementation::noInitAllocate<T>(size) : nullptr}, _size{size}, _deleter{Implementation::noInitDeleter<T>()} {}
explicit Array(Corrade::NoInitT, std::size_t size): _data{size ? Implementation::noInitAllocate<T>(size) : nullptr}, _size{size}, _deleter{Implementation::noInitDeleter<T>()} {}

/**
* @brief Construct a direct-initialized array
Expand All @@ -382,7 +381,7 @@ class Array {
* constructor and then initializes each element with placement new
* using forwarded @p args.
*/
template<class... Args> explicit Array(DirectInitT, std::size_t size, Args&&... args);
template<class... Args> explicit Array(Corrade::DirectInitT, std::size_t size, Args&&... args);

/**
* @brief Construct a list-initialized array
Expand All @@ -397,15 +396,15 @@ class Array {
* @ref Containers-Array-initializer-list "class documentation" for
* more information.
*/
/*implicit*/ Array(InPlaceInitT, std::initializer_list<T> list);
/*implicit*/ Array(Corrade::InPlaceInitT, std::initializer_list<T> list);

/**
* @brief Construct a value-initialized array
*
* Alias to @ref Array(ValueInitT, std::size_t).
* @see @ref Array(DefaultInitT, std::size_t)
*/
explicit Array(std::size_t size): Array{ValueInit, size} {}
explicit Array(std::size_t size): Array{Corrade::ValueInit, size} {}

/**
* @brief Wrap an existing array
Expand Down Expand Up @@ -694,7 +693,7 @@ usability issues as with @ref std::vector --- see the
information.
*/
template<class T> inline Array<T> array(std::initializer_list<T> list) {
return Array<T>{InPlaceInit, list};
return Array<T>{Corrade::InPlaceInit, list};
}

/** @relatesalso ArrayView
Expand Down Expand Up @@ -750,7 +749,7 @@ template<class T, class D> inline Array<T, D>::Array(Array<T, D>&& other) noexce
other._deleter = D{};
}

template<class T, class D> template<class ...Args> Array<T, D>::Array(DirectInitT, std::size_t size, Args&&... args): Array{NoInit, size} {
template<class T, class D> template<class ...Args> Array<T, D>::Array(Corrade::DirectInitT, std::size_t size, Args&&... args): Array{Corrade::NoInit, size} {
for(std::size_t i = 0; i != size; ++i)
/* This works around a featurebug in C++ where new T{} doesn't work for
an explicit defaulted constructor. Additionally it works around GCC
Expand All @@ -759,7 +758,7 @@ template<class T, class D> template<class ...Args> Array<T, D>::Array(DirectInit
Implementation::construct(_data[i], std::forward<Args>(args)...);
}

template<class T, class D> Array<T, D>::Array(InPlaceInitT, std::initializer_list<T> list): Array{NoInit, list.size()} {
template<class T, class D> Array<T, D>::Array(Corrade::InPlaceInitT, std::initializer_list<T> list): Array{Corrade::NoInit, list.size()} {
std::size_t i = 0;
for(const T& item: list)
/* Can't use {}, see the GCC 4.8-specific overload for details */
Expand Down
8 changes: 4 additions & 4 deletions src/Corrade/Containers/ArrayTuple.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
#include <initializer_list>
#include <utility>

#include "Corrade/Tags.h"
#include "Corrade/Containers/Containers.h"
#include "Corrade/Containers/constructHelpers.h"
#include "Corrade/Containers/Tags.h"
#include "Corrade/Utility/visibility.h"

namespace Corrade { namespace Containers {
Expand Down Expand Up @@ -288,7 +288,7 @@ class ArrayTuple::Item {
* use @ref Item(NoInitT, std::size_t, ArrayView<T>&) instead and then
* manually construct each item in-place.
*/
template<class T> /*implicit*/ Item(ValueInitT, std::size_t size, ArrayView<T>& outputView): Item{NoInit, size, outputView} {
template<class T> /*implicit*/ Item(Corrade::ValueInitT, std::size_t size, ArrayView<T>& outputView): Item{Corrade::NoInit, size, outputView} {
static_assert(std::is_default_constructible<T>::value,
"can't default-init a type with no default constructor, use NoInit instead and manually initialize each item");
_constructor = [](void* data) {
Expand All @@ -303,7 +303,7 @@ class ArrayTuple::Item {
*
* Alias to @ref Item(ValueInitT, std::size_t, ArrayView<T>&).
*/
template<class T> /*implicit*/ Item(std::size_t size, ArrayView<T>& outputView): Item{ValueInit, size, outputView} {}
template<class T> /*implicit*/ Item(std::size_t size, ArrayView<T>& outputView): Item{Corrade::ValueInit, size, outputView} {}

/**
* @brief Construct a view without initializing its elements
Expand All @@ -317,7 +317,7 @@ class ArrayTuple::Item {
* gets finally called on *all elements*, regardless of whether they
* were properly constructed or not.
*/
template<class T> /*implicit*/ Item(NoInitT, std::size_t size, ArrayView<T>& outputView):
template<class T> /*implicit*/ Item(Corrade::NoInitT, std::size_t size, ArrayView<T>& outputView):
_elementSize{sizeof(T)}, _elementAlignment{alignof(T)}, _elementCount{size},
_constructor{},
_destructor{std::is_trivially_destructible<T>::value ? static_cast<void(*)(char*, std::size_t)>(nullptr) :
Expand Down
2 changes: 1 addition & 1 deletion src/Corrade/Containers/BigEnumSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class BigEnumSet {
*
* The contents are left in an undefined state.
*/
explicit BigEnumSet(NoInitT) {}
explicit BigEnumSet(Corrade::NoInitT) {}

/** @brief Equality comparison */
constexpr bool operator==(const BigEnumSet<T, size>& other) const {
Expand Down
7 changes: 5 additions & 2 deletions src/Corrade/Containers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,15 @@ set(CorradeContainers_HEADERS
StridedArrayView.h
String.h
StringStl.h
StringView.h
Tags.h)
StringView.h)

set(CorradeContainers_PRIVATE_HEADERS
Implementation/RawForwardList.h)

if(CORRADE_BUILD_DEPRECATED)
list(APPEND CorradeContainers_HEADERS Tags.h)
endif()

# Sources are compiled as part of Utility

# Force IDEs to display all header files in project view
Expand Down
Loading

0 comments on commit c0267de

Please sign in to comment.