Use the latest STL implementation regardless of your C++ version (C++14 ~)
// All implementations are written under C++14 standard semantics
#include "preview/ranges.h"
auto map = preview::views::iota('A', 'E') |
preview::views::enumerate |
preview::ranges::to<std::map>(); // See notes about CTAD below
std::cout << map[0] << ' '
<< map[1] << ' '
<< map[2] << '\n';
// A B C
preview
is standard-conforming, and is compatible with existing STL
// Pre-C++20 iterators are fully compatible
auto floats = std::istringstream{"1.1 2.2\t3.3\v4.4\f55\n66\r7.7 8.8"};
ranges::copy(views::istream<float>(floats), std::ostream_iterator<float>{std::cout, ", "});
// Complex ranges/iterators are also compatible with both pre C++20 and
// post C++20 std::iterator_traits
auto r = preview::views::iota(0) |
preview::views::take(10) |
preview::views::filter([](auto x) { return x % 2 == 0; });
static_assert(std::is_same<
std::iterator_traits<decltype(r.begin())>::reference,
int
>::value, "");
Up to C++26 STL are available
void foo(preview::span<int>) {}
int main() {
// span with C++26 standard
foo({1, 2, 3});
preview::variant<int, float, double> v{1.0f};
v.visit([](auto x) {
// member visit(): C++26 standard
});
// views::concat
std::vector<char> v = {'h', 'e', 'l'};
std::string s = "lo, ";
preview::string_view sv = "world";
std::list<char> l = {'!'};
// hello, world!
for (auto c : preview::views::concat(v, s, sv, l)) {
std::cout << c;
}
// expected
auto process = [](preview::string_view str) -> preview::expected<int, std::string> {
return parse_number(str)
.transform([](double v) { return static_cast<int>(v); })
.transform_error([](parse_error e) {
return e == parse_error::invalid_input ? "invalid input" : "overflow";
});
};
std::cout << process("42").value_or(-1) << '\n;'; // 42
std::cout << process("inf").value_or(-1) << '\n'; // -1
}
Compiler | Minimum version tested | Maximum version tested |
---|---|---|
MSVC | 19.29.30154.0 (Visual Studio 16 2019) | 19.40.33811.0 (Visual Studio 17 2022) |
gcc | 9.5.0 | 13.1.0 |
clang | 11.1.0 | 15.0.7 |
Apple clang | 14.0.0.14000029 | 15.0.0.15000040 (Silicon) |
Android NDK | r18 (clang 7.0) | r26 (clang 17.0.2) |
Emscripten | 3.1.20 (clang 16.0.0) | latest(3.1.61) (clang 19.0.0) |
Copy this repository under your project and use add_subdirectory
add_subdirectory(path/to/preview)
target_link_libraries(your-project INTERFACE preview)
Although it is not recommended, you can just copy & paste files under include/
into your project.
- Note: Without CMake configuration, heuristic compiler/STL checks will be performed.
With the reason stated in Non-CMake, installation is possible but not recommended.
Implementation available in C++14 ~ :
Description
: C++YY standard implemented in C++XX
: C++YY standard, not implemented yet
- If the implementation is impossible(i.e., needs compiler support / hardware info) it is marked as N/A
- Some features are working in progress
- Introduced: First introduced version
- Revision: Behavior changed/updated version
Introduced | Revision | |
---|---|---|
any |
||
bad_any_cast |
||
swap(any) |
||
make_any |
||
any_cast |
Introduced | Revision | |
---|---|---|
to_array |
Introduced | Revision | |
---|---|---|
barrier |
Introduced | Revision | |
---|---|---|
endian |
||
bit_cast |
||
byteswap |
||
has_single_bit |
||
bit_ceil |
||
bit_floor |
||
bit_width |
||
rotl |
||
rotr |
||
countl_zero |
||
countl_one |
||
countr_zero |
||
countr_one |
||
popcount |
Introduced | Revision | |
---|---|---|
chars_format |
||
from_chars_result |
||
to_chars_result |
||
from_chars |
||
to_chars |
N/A
N/A
Introduced | Revision | |
---|---|---|
byte |
||
to_integer |
Introduced | Revision | |
---|---|---|
breakpoint |
||
breakpoint_if_debugging |
||
is_debugger_present |
Introduced | Revision | |
---|---|---|
uncaught_exceptions |
Introduced | Revision | |
---|---|---|
expected |
||
unexpected |
||
bad_expected_access |
||
unexpect unexpect_t |
N/A
Introduced | Revision | |
---|---|---|
flat_map |
||
flat_multimap |
||
sorted_unique sorted_unique_t |
||
sorted_equivalent sorted_equivalent_t |
Introduced | Revision | |
---|---|---|
flat_set |
||
flat_multiset |
N/A
Introduced | Revision | |
---|---|---|
hazard_pointer_obj_base |
||
hazard_pointer |
||
make_hazard_pointer |
Introduced | Revision | |
---|---|---|
inplace_vector |
- Notes
contiguous_iterator_tag
- Alias to
std::contiguous_iterator_tag
if defined,preview::detail::pseudo_contiguous_iterator_tag
otherwise.
- Alias to
contiguous_iterator<I>
- May incorrectly evaluates to
true
for somerandom_access_iterator
ifI::iterator_category
does not satisfyderived_from<contiguous_iterator_tag>
(typically before C++20) - Following pre-C++20 iterators explicitly evaluates to
false
std::vector<bool>::xxx_iterator
std::deque<T>::xxx_iterator
- May incorrectly evaluates to
projected
- Indirect layer doesn't work without using concepts.
Check
preview::projectable
before usingpreview::projected
directly.
- Indirect layer doesn't work without using concepts.
Check
Introduced | Revision | |
---|---|---|
latch |
Introduced | Revision | |
---|---|---|
mdspan |
||
extents |
||
layout_left |
||
layout_right |
||
layout_stride |
||
layout_stride |
||
submdspan |
||
submdspan_extents |
||
strided_slice |
||
submdspan_mapping_result |
||
full_extent full_extent_t |
N/A
Introduced | Revision | |
---|---|---|
scoped_lock |
Introduced | Revision | |
---|---|---|
align_val_t |
||
hardware_destructive_interference_size |
||
hardware_constructive_interference_size |
||
launder |
||
destroying_delete destroying_delete_t |
Introduced | Revision | |
---|---|---|
e |
||
log2e |
||
log10e |
||
pi |
||
inv_pi |
||
inv_sqrtpi |
||
ln2 |
||
ln10 |
||
sqrt2 |
||
sqrt3 |
||
inv_sqrt3 |
||
egamma |
||
phi |
Introduced | Revision | |
---|---|---|
exclusive_scan |
||
transform_exclusive_scan |
||
inclusive_scan |
||
transform_inclusive_scan |
||
gcd |
||
lcm |
||
reduce |
||
transform_reduce |
||
midpoint |
||
ranges::iota |
||
add_sat |
||
sub_sat |
||
mul_sat |
||
div_sat |
||
saturate_cast |
Introduced | Revision | |
---|---|---|
print |
||
println |
||
vprint_unicode |
||
vprint_unicode_buffered |
||
vprint_nonunicode |
||
vprint_nonunicode_buffered |
Introduced | Revision | |
---|---|---|
optional |
||
bad_optional_access |
||
std::hash<optional> |
||
nullopt |
||
nullopt_t |
||
swap(optional) |
||
make_optional |
Introduced | Revision | |
---|---|---|
uniform_random_bit_generator |
- Notes
- CTAD for
Args...
may be incorrect before C++17 - Equipped with C++23 conversions(e.g.,
pair-like
->std::pair
)
- CTAD for
Introduced | Revision | |
---|---|---|
rcu_obj_base |
||
rcu_domain |
||
rcu_default_domain |
||
rcu_synchronize |
||
rcu_barrier |
||
rcu_retire |
Introduced | Revision | |
---|---|---|
counting_semaphore |
||
binary_semaphore |
Introduced | Revision | |
---|---|---|
shared_mutex |
Introduced | Revision | |
---|---|---|
stop_token |
||
stop_source |
||
stop_callback |
||
nostopstate_t |
||
nostopstate |
Introduced | Revision | |
---|---|---|
erase(std::basic_string) |
||
erase_if(std::basic_string) |
Introduced | Revision | |
---|---|---|
basic_string_view |
||
std::hash<basic_string_view> |
||
swap(optional) |
||
operator""_sv |
N/A
Introduced | Revision | |
---|---|---|
source_location |
Introduced | Revision | |
---|---|---|
basic_syncbuf |
||
basic_osyncstream |
||
std::swap(basic_syncbuf) |
Introduced | Revision | |
---|---|---|
span |
||
dynamic_extent |
||
as_bytes |
||
as_writable_bytes |
Introduced | Revision | |
---|---|---|
basic_spanbuf |
||
basic_ispanstream |
||
basic_ospanstream |
||
basic_spanstream |
Introduced | Revision | |
---|---|---|
stacktrace_entry |
||
basic_stacktrace |
||
hash<stracktrace_entry> |
||
hash<basic_stacktrace> |
Introduced | Revision | |
---|---|---|
text_encoding |
Introduced | Revision | |
---|---|---|
jthread |
Introduced | Revision | |
---|---|---|
apply |
||
make_from_tuple |
- Notes
common_type
- If
common_type
fails to define member typedeftype
, it falls back tostd::common_type
struct common_a {}; struct common_b {}; struct common_c {}; template<> struct std::common_type<common_a, common_b> { using type = common_c; }; // fallback to std::common_type for user specialization types static_assert(std::is_same_v<preview::common_type_t<common_a, common_b>, common_c>); // MSVC and GCC (before C++23) does not satisfy C++23 standard for std::common_type<tuple-like> static_assert(std::is_same_v< std::common_type_t<std::tuple<int, int>, std::pair<int, double>>, std::pair<int, int>>); // Since std::common_type does not satisfy C++23, preview::common_type does not fallback to std::common_type static_assert(std::is_same_v< preview::common_type_t< std::tuple<int, int>, std::pair<int, double>>, std::pair<int, double>>);
- If
Introduced | Revision | |
---|---|---|
as_const |
||
in_place in_place_t |
||
cmp_equal ... |
||
in_range |
||
forward_like |
||
to_underlying |
||
unreachable |
||
nontype nontype_t |
Introduced | Revision | |
---|---|---|
variant |
||
monostate |
||
bad_variant_access |
||
variant_size |
||
variant_alternative |
||
std::hash<variant> |
||
variant_npos |
||
visit |
||
get_if |
Introduced | Revision | |
---|---|---|