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.16.27051.0 (Visual Studio 2017) | 19.40.33811.0 (Visual Studio 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) |
MinGW | 13.1.0 | 14.2.0 |
Intel C++ | ? | icx 2024.2 |
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 ~ :
Header | Total | C++17 | C++20 | C++23 | C++26 | |
---|---|---|---|---|---|---|
algorithm | ||||||
any | ||||||
array | ||||||
bit | ||||||
concepts | ||||||
cstddef | ||||||
expected | ||||||
functional | ||||||
iterator | ||||||
memory | ||||||
numbers | ||||||
numeric | ||||||
optional | ||||||
random | ||||||
ranges | ||||||
span | ||||||
string_view | * | |||||
tuple | ||||||
type_traits | ||||||
utility | ||||||
variant | ||||||
atomic | ||||||
barrier | ||||||
charconv | ||||||
chrono | ||||||
cmath | ||||||
compare | ||||||
coroutine | N/A | |||||
debugging | ||||||
exception | ||||||
execution | ||||||
flat_map | ||||||
flat_set | ||||||
format | ||||||
filesystem | N/A | |||||
hazard_pointer | ||||||
inplace_vector | ||||||
latch | ||||||
linalg | ||||||
mdspan | ||||||
memory_resource | ||||||
mutex | ||||||
new | ||||||
rcu | ||||||
semaphore | ||||||
shared_mutex | ||||||
stop_token | ||||||
string | ||||||
source_location | N/A | |||||
syncstream | ||||||
spanstream | ||||||
stacktrace | N/A | |||||
text_encoding | ||||||
thread | ||||||
version |
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 |
- Notes
preview::any
preview::any
is an alias ofstd::any
if using C++17 or later to prevent implicit construction ofstd::any
frompreview::any
and vice-versa. See any.h for more detail.
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 |
(N/A) |
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
- Notes
reference_wrapper
- Non-standard member function
operator*()
is defined only for the purpose of mixed use withstd::invoke
. - Before C++20,
preview::reference_wrapper
cannot be used in deduced context ofstd::reference_wrapper
. In sucn case, non-standard member functionto_std()
can be used.template<typename T> void foo(std::reference_wrapper<T> x) {} int main() { int x = 10; auto ref = preview::ref(x); foo(ref); // Compile error before C++20 foo(ref.to_std()); std::cout << std::boolalpha << (ref == 10) << std::endl; }
- Non-standard member function
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 |
- Notes
to_address
- If
std::pointer_traits::to_address
is available, it is used beforepreview::pointer_traits::to_address
.⚠️ std::pointer_traits::to_address
is not sfinae-friendly until MSVC 2022, so not used.
- If
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 |
- Notes
nullopt
,nullopt_t
std::nullopt
is used if available,preview::nullopt
otherwise.
- C++26
Introduced | Revision | |
---|---|---|
uniform_random_bit_generator |
- Notes
ranges::to
- CTAD for
Args...
may be incorrect before C++17 - Equipped with C++23 conversions(e.g.,
pair-like
->std::pair
)
- CTAD for
ranges::concat_view
- Implemented before standardization
- Needs update
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) |
||
basic_string |
Introduced | Revision | |
---|---|---|
basic_string_view |
* | |
std::hash<basic_string_view> |
||
operator""_sv |
- Notes
- C++26
- P2591 (R5)
- P2697 (R1)
- Implemented as
preview::basic_string_view::operator bitset
- Implemented as
- P2495 (R3)
- Implemented as
preview::basic_string_view::operator string-streams
- Memory allocation is performed (conversion to
std::basic_string
)
- Implemented as
- C++26
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 |
||
tuple_like pair_like |
||
basic_common_reference<tuple-like> |
||
common_type<tuple-like> |
||
formatter<tuple-like> |
- 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 |
N/A | |
nontype nontype_t |
Introduced | Revision | |
---|---|---|
variant |
||
monostate |
||
bad_variant_access |
||
variant_size |
||
variant_alternative |
||
std::hash<variant> |
||
variant_npos |
||
visit |
||
get_if |
Introduced | Revision | |
---|---|---|