template<class T>
class utils::FixedArray< T >
A fixed-size array with the size determined at runtime.
The array allows initializing each of the array elements with the same parameters:
class NonDefaultConstructible final {
public:
explicit NonDefaultConstructible(std::string str)
: str_(std::move(str))
{}
std::string GetString() const { return str_; }
private:
std::string str_;
};
ASSERT_EQ(array.size(), 42);
ASSERT_EQ(array[0].GetString(), "The string");
ASSERT_EQ(array[14].GetString(), "The string");
ASSERT_EQ(array[41].GetString(), "The string");
The array also allows initializing each of the array elements with the output of a generator function:
using NonMovable = std::atomic<std::size_t>;
constexpr std::size_t kObjectCount = 42;
EXPECT_EQ(array.size(), kObjectCount);
EXPECT_FALSE(array.empty());
std::size_t index = 0;
for (const auto& item : array) {
EXPECT_EQ(item.load(), index++);
}
EXPECT_EQ(index, kObjectCount);
Definition at line 29 of file fixed_array.hpp.
|
|
| FixedArray ()=default |
| | Make an empty array.
|
| |
| template<class... Args> |
| | FixedArray (std::size_t size, Args &&... args) |
| | Make an array and initialize each element with "args".
|
| |
| | FixedArray (FixedArray &&other) noexcept |
| |
| FixedArray & | operator= (FixedArray &&other) noexcept |
| |
|
| FixedArray (const FixedArray &)=delete |
| |
|
FixedArray & | operator= (const FixedArray &)=delete |
| |
| std::size_t | size () const noexcept |
| |
| bool | empty () const noexcept |
| |
| const T & | operator[] (std::size_t i) const noexcept USERVER_IMPL_LIFETIME_BOUND |
| |
| T & | operator[] (std::size_t i) noexcept USERVER_IMPL_LIFETIME_BOUND |
| |
| T & | front () noexcept USERVER_IMPL_LIFETIME_BOUND |
| |
| const T & | front () const noexcept USERVER_IMPL_LIFETIME_BOUND |
| |
| T & | back () noexcept USERVER_IMPL_LIFETIME_BOUND |
| |
| const T & | back () const noexcept USERVER_IMPL_LIFETIME_BOUND |
| |
| T * | data () noexcept USERVER_IMPL_LIFETIME_BOUND |
| |
| const T * | data () const noexcept USERVER_IMPL_LIFETIME_BOUND |
| |
| T * | begin () noexcept USERVER_IMPL_LIFETIME_BOUND |
| |
| T * | end () noexcept USERVER_IMPL_LIFETIME_BOUND |
| |
| const T * | begin () const noexcept USERVER_IMPL_LIFETIME_BOUND |
| |
| const T * | end () const noexcept USERVER_IMPL_LIFETIME_BOUND |
| |
| const T * | cbegin () const noexcept USERVER_IMPL_LIFETIME_BOUND |
| |
| const T * | cend () const noexcept USERVER_IMPL_LIFETIME_BOUND |
| |
| template<class GeneratorFunc> |
| | FixedArray (impl::InternalTag, std::size_t size, GeneratorFunc &&generator) |
| |