Skip to content

Commit

Permalink
Add ring (default) constructor for use with a fixed array type as the…
Browse files Browse the repository at this point in the history
… container (#33, thanks @Crzyrndm)
  • Loading branch information
martinmoene committed May 18, 2024
1 parent df513eb commit c03e130
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions include/nonstd/ring.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ class ring
typedef typename RingSpan::const_reverse_iterator const_reverse_iterator;
#endif

#if nsrs_CPP11_OR_GREATER
nsrs_REQUIRES_0( !std::is_constructible<Container, size_t>::value )
explicit ring()
: cont{}
, rs( std::begin(cont), std::end(cont) )
{}
#endif

explicit ring( size_type capacity )
: cont( capacity )
, rs( cont.begin(), cont.end() )
Expand Down
15 changes: 15 additions & 0 deletions test/ring-span.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

#include nsrs_RING_SPAN_LITE_T_HEADER

#if nsrs_CPP11_OR_GREATER
# include <array>
#endif

#include <numeric>

using namespace nonstd;
Expand Down Expand Up @@ -1258,6 +1262,17 @@ CASE( "ring: Allows to create data owning ring from container - capacity is powe
#endif
}

// issue-33: std::array

CASE( "ring: Allows to create data owning ring from std::array (C++11)" )
{
#if nsrs_CPP11_OR_GREATER
ring< std::array<int, 3 >> r;
#else
EXPECT( !!"std::array is not available (no C++11)" );
#endif
}

CASE( "tweak header: reads tweak header if supported " "[tweak]" )
{
#if nsrs_HAVE_TWEAK_HEADER
Expand Down

0 comments on commit c03e130

Please sign in to comment.