Skip to content

Commit a85d952

Browse files
Add istream example
1 parent 80cabd0 commit a85d952

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

examples/CMakeLists.txt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
22

3-
function(beman_add_example)
4-
beman_add_executable(${ARGN} CATEGORY examples)
3+
function(beman_add_examples)
4+
foreach(name ${ARGN})
5+
beman_add_executable(
6+
TARGET ${name}
7+
SOURCES ${name}.cpp
8+
CATEGORY examples
9+
)
10+
endforeach()
511
endfunction()
612

7-
beman_add_example(TARGET sum_views)
13+
beman_add_examples(
14+
istream
15+
sum_views
16+
)

examples/istream.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2+
3+
#include <beman/any_view/any_view.hpp>
4+
5+
#include <algorithm>
6+
#include <iostream>
7+
#include <sstream>
8+
#include <ranges>
9+
10+
namespace bav = beman::any_view;
11+
12+
int main() {
13+
std::istringstream in{"1 2 3 4"};
14+
bav::any_view<const int> view{std::views::istream<int>(in)};
15+
std::ostream_iterator<int> out{std::cout, ", "};
16+
17+
std::ranges::copy(view, out);
18+
std::cout << std::endl;
19+
20+
return 0;
21+
}

examples/sum_views.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include <vector>
88

99
namespace bav = beman::any_view;
10-
using opt = bav::any_view_options;
1110

1211
auto sum(bav::any_view<const int> v1, bav::any_view<const int> v2) {
1312
auto result = 0;

include/beman/any_view/detail/iterator_adaptor.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ class iterator_adaptor final : public iterator_interface<ElementT, RefT, RValueR
3737
}
3838

3939
public:
40+
constexpr iterator_adaptor() noexcept(std::is_nothrow_default_constructible_v<IteratorT> and
41+
std::is_nothrow_default_constructible_v<SentinelT>) = default;
42+
43+
constexpr iterator_adaptor(const iterator_adaptor&) = default;
44+
45+
constexpr iterator_adaptor(iterator_adaptor&&) noexcept(std::is_nothrow_move_constructible_v<IteratorT> and
46+
std::is_nothrow_move_constructible_v<SentinelT>) = default;
47+
4048
constexpr iterator_adaptor(IteratorT&& iterator, SentinelT&& sentinel) noexcept(get_noexcept())
4149
: iterator(std::move(iterator)), sentinel(std::move(sentinel)) {}
4250

0 commit comments

Comments
 (0)