Skip to content

Commit

Permalink
[MISC] rename view:: to views::
Browse files Browse the repository at this point in the history
  • Loading branch information
h-2 committed Sep 10, 2019
1 parent c9db639 commit 8c65076
Show file tree
Hide file tree
Showing 285 changed files with 2,293 additions and 2,280 deletions.
40 changes: 20 additions & 20 deletions doc/howto/write_a_view/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ std::ranges::transform_view v{vec, l};
But this syntax gets difficult to read when you create "a view(from a view(from a view()))".
That's why for every view that adapts an existing view we have an additional *adaptor object*, usually available
in a `view::` sub-namespace:
in a `views::` sub-namespace:
```cpp
std::vector vec{1, 2, 3, 4, 5};
auto l = [] (int i) { return i + 1; };
auto v = vec | std::view::transform(l);
auto v = vec | std::views::transform(l);
```

This adaptor object (`std::view::transform`) provides the pipe operator and returns an object of the actual view type
This adaptor object (`std::views::transform`) provides the pipe operator and returns an object of the actual view type
(`std::ranges::transform_view`).
The pipe operator allows us to chain multiple adaptors similar to the unix command line.
We will discuss the details of these adaptor objects in the following sections.
Expand All @@ -73,21 +73,21 @@ The wording of the standard needs some getting used to, but some important notes
what we did above):
```cpp
std::vector vec{1, 2, 3, 4, 5};
auto v = vec | std::view::transform([] (int i) { return i + 1; })
| std::view::filter([] (int i) { return i % 2 == 0; });
auto v = vec | std::views::transform([] (int i) { return i + 1; })
| std::views::filter([] (int i) { return i % 2 == 0; });
// v is a view, you can iterate over it!
```
2. The adaptor objects support function-style usage, too, although it only reduces readability:
```cpp
std::vector vec{1, 2, 3, 4, 5};
auto v = std::view::filter(std::view::transform(vec, [] (int i) { return i + 1; }), [] (int i) { return i % 2 == 0; });
auto v = std::views::filter(std::views::transform(vec, [] (int i) { return i + 1; }), [] (int i) { return i % 2 == 0; });
// v is a view, you can iterate over it!
```

3. You can create a new *adaptor closure object* from an adaptor object that requires parameters by providing those:
```cpp
std::vector vec{1, 2, 3, 4, 5};
auto a = std::view::transform([] (int i) { return i + 1; });
auto a = std::views::transform([] (int i) { return i + 1; });
// a is an adaptor and can be used as such:
auto v = vec | a;
```
Expand All @@ -96,17 +96,17 @@ auto v = vec | a;
a range:
```cpp
std::vector vec{1, 2, 3, 4, 5};
auto a = std::view::transform([] (int i) { return i + 1; })
| std::view::filter([] (int i) { return i % 2 == 0; });
auto a = std::views::transform([] (int i) { return i + 1; })
| std::views::filter([] (int i) { return i % 2 == 0; });
// a is an adaptor and can be used as such:
auto v = vec | a;
```

| Terminology | Description | Example |
|--------------------------------|---------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------|
| "view" | A type that models std::ranges::view. | `std::ranges::filter_view<std::subrange<int const *, int const *>>` |
| "view adaptor object" | Creates a view; can be combined with other adaptors. | `std::view::reverse` and <br> `std::view::filter` and <br> `(std::view::filter([] (int) { return true; }))` |
| "view adaptor closure object" | A "view adaptor object" that requires no paramaters other than the range. | `std::view::reverse` and \strike{<tt>std::view::filter</tt> and} `(std::view::filter([] (int) { return true; }))` |
| "view adaptor object" | Creates a view; can be combined with other adaptors. | `std::views::reverse` and <br> `std::views::filter` and <br> `(std::views::filter([] (int) { return true; }))` |
| "view adaptor closure object" | A "view adaptor object" that requires no paramaters other than the range. | `std::views::reverse` and \strike{<tt>std::views::filter</tt> and} `(std::views::filter([] (int) { return true; }))` |

In many cases where you are planning on creating "a new view", it will be sufficient to use the previously
mentioned techniques to just create "a new adaptor object" and not having to specify the actual view type yourself.
Expand All @@ -131,7 +131,7 @@ Define a *range adaptor object* using an existing adaptor which applies a concre
(calling seqan3::to_char) on every element.

\hint
You need to need use `std::view::transform` and you need to set a fixed transformation function. `std::view::transform`
You need to need use `std::views::transform` and you need to set a fixed transformation function. `std::views::transform`
takes an object that models `std::regular_invocable`, e.g. a lambda function with empty capture `[]`.
\endhint

Expand All @@ -142,7 +142,7 @@ takes an object that models `std::regular_invocable`, e.g. a lambda function wit

\include doc/howto/write_a_view/view_exercise1.cpp

You simply define your adaptor type as `auto` and make it behave like `std::view::transform`, except that you
You simply define your adaptor type as `auto` and make it behave like `std::views::transform`, except that you
"hard-code" the lambda function that is applied to each element.
Since your adaptor object now takes a range as the only parameter, it is an adaptor closure object.

Expand All @@ -156,7 +156,7 @@ Study the `seqan3::nucleotide_alphabet`. It states that you can call `seqan3::co
which will give you <tt>'A'_dna5</tt> for <tt>'T'_dna5</tt> a.s.o. Think about how you can adapt the previous solution
to write a view that transforms ranges of nucleotides into their complement.

BUT, we are also interested in *reversing* the range which is possible with `std::view::reverse`:
BUT, we are also interested in *reversing* the range which is possible with `std::views::reverse`:

\snippet doc/howto/write_a_view/view_exercise2.cpp start
```cpp
Expand All @@ -171,7 +171,7 @@ Define a *range adaptor object* that presents a view of the reverse complement o

\include doc/howto/write_a_view/view_exercise2.cpp

The adaptor consists of `std::view::reverse` combined with `std::view::transform`. This time the lambda just
The adaptor consists of `std::views::reverse` combined with `std::views::transform`. This time the lambda just
performs the call to `seqan3::complement`.
\endsolution

Expand Down Expand Up @@ -374,11 +374,11 @@ The second constructor is more interesting, it takes a `std::ranges::viewable_ra
being either a `std::ranges::view` or a reference to `std::ranges::range` that is not a view
(e.g. `std::vector<char> &`).
Since we have a constructor for `std::ranges::view` already, this one explicitly handles the second case
and goes through `std::view::all` which wraps the reference in a thin view-layer.
and goes through `std::views::all` which wraps the reference in a thin view-layer.
Storing only a view member guarantess that our type itself is also cheap to copy among other things.

Note that both of these constructors seem like generic functions, but they just handle the underlying type or a
type that turns into the underlying when wrapped in `std::view::all`.
type that turns into the underlying when wrapped in `std::views::all`.

\snippet doc/howto/write_a_view/solution_view.cpp view_deduction_guide

Expand Down Expand Up @@ -421,10 +421,10 @@ function/constructor-style creation of view objects, therefore it defines two op
\snippet doc/howto/write_a_view/solution_view.cpp adaptor_type_definition

The first operator is very straight-forward, it simply delegates to the constructor of our view so that
`view::my(FOO)` is identical to `my_view{FOO}`.
`views::my(FOO)` is identical to `my_view{FOO}`.

The second operator is declared as friend, because the left-hand-side of the `operator|` is generic, it's how
the range is handled in snippets like `auto v = vec | view::my`.
the range is handled in snippets like `auto v = vec | views::my`.

\note
This adaptor type does not yet provide the ability to combine multiple adaptors into a new adaptor, it only
Expand All @@ -447,7 +447,7 @@ The adaptor object is simply an instance of the previously defined type:

\snippet doc/howto/write_a_view/solution_view.cpp adaptor_object_definition

As noted above, we place this object in a `view::` sub-namespace by convention.
As noted above, we place this object in a `views::` sub-namespace by convention.
Since the object holds no state, we mark it as `constexpr` and since it's a global variable we also mark it as
`inline` to prevent linkage issues.

Expand Down
6 changes: 3 additions & 3 deletions doc/howto/write_a_view/solution_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class my_view : public std::ranges::view_interface<my_view<urng_t>>

// construct from non-view that can be view-wrapped
template <std::ranges::viewable_range orng_t>
my_view(orng_t && urange_) : urange{std::view::all(std::forward<orng_t>(urange_))}
my_view(orng_t && urange_) : urange{std::views::all(std::forward<orng_t>(urange_))}
{}
//![view_constructors]

Expand Down Expand Up @@ -143,7 +143,7 @@ struct my_view_fn

//![adaptor_object_definition]
/* The adaptor object's definition */
namespace view
namespace views
{

inline constexpr my_view_fn my{};
Expand Down Expand Up @@ -175,7 +175,7 @@ int main()

//![main_adaptor]
/* try the adaptor */
auto v2 = vec | std::view::reverse | ::view::my;
auto v2 = vec | std::views::reverse | ::views::my;
static_assert(std::ranges::random_access_range<decltype(v2)>);
debug_stream << v2 << '\n';
//![main_adaptor]
Expand Down
2 changes: 1 addition & 1 deletion doc/howto/write_a_view/view_exercise1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using namespace seqan3;

//![start]
auto const my_convert_to_char_view = std::view::transform([] (auto const alph)
auto const my_convert_to_char_view = std::views::transform([] (auto const alph)
{
return to_char(alph);
});
Expand Down
2 changes: 1 addition & 1 deletion doc/howto/write_a_view/view_exercise2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using namespace seqan3;

//![start]
auto my_reverse_complement = std::view::reverse | std::view::transform([] (auto const d)
auto my_reverse_complement = std::views::reverse | std::views::transform([] (auto const d)
{
return complement(d);
});
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial/alignment_file/alignment_file_solution1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ write_file_dummy_struct go{};
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/io/alignment_file/all.hpp>
#include <seqan3/std/filesystem>
#include <seqan3/range/view/get.hpp>
#include <seqan3/range/views/get.hpp>
#include <seqan3/std/ranges>

using namespace seqan3;
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial/alignment_file/alignment_file_solution2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ int main()
ref_seqs,
fields<field::ID,field::REF_ID, field::MAPQ, field::ALIGNMENT>{}};

auto mapq_filter = std::view::filter([] (auto & rec) { return get<field::MAPQ>(rec) >= 30; });
auto mapq_filter = std::views::filter([] (auto & rec) { return get<field::MAPQ>(rec) >= 30; });

for (auto & [id, ref_id, mapq, alignment] : mapping_file | mapq_filter)
{
Expand Down
4 changes: 2 additions & 2 deletions doc/tutorial/alphabet/alphabet_gc_content.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <seqan3/alphabet/all.hpp>
#include <seqan3/argument_parser/all.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/range/view/char_to.hpp>
#include <seqan3/range/views/char_to.hpp>

using namespace seqan3;

Expand All @@ -26,7 +26,7 @@ int main (int argc, char * argv[])
}

// Convert the input to a dna5 sequence.
std::vector<dna5> sequence{input | view::char_to<dna5>};
std::vector<dna5> sequence{input | views::char_to<dna5>};

// Initialise an array with count values for dna5 symbols.
std::array<size_t, dna5::alphabet_size> count{}; // default initialised with zeroes
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial/argument_parser/solution3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void run_program(std::filesystem::path & path, uint32_t yr, std::string & aggr_b

while (std::getline(file, line))
{
auto splitted_line = line | std::view::split('\t');
auto splitted_line = line | std::views::split('\t');
auto it = std::next(splitted_line.begin(), 3); // move to 4th column

if (to_number<uint32_t>(*it) >= yr)
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial/argument_parser/solution4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void run_program(std::filesystem::path & path, std::vector<uint8_t> sn, std::str
//![altered_while]
while (std::getline(file, line))
{
auto splitted_line = line | std::view::split('\t');
auto splitted_line = line | std::views::split('\t');
auto it = splitted_line.begin(); // move to 1rst column

if (std::find(sn.begin(), sn.end(), to_number<uint8_t>(*it)) != sn.end())
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial/argument_parser/solution5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void run_program(std::filesystem::path & path, std::vector<uint8_t> sn, std::str

while (std::getline(file, line))
{
auto splitted_line = line | std::view::split('\t');
auto splitted_line = line | std::views::split('\t');
auto it = splitted_line.begin(); // move to 1rst column

if (std::find(sn.begin(), sn.end(), to_number<uint8_t>(*it)) != sn.end())
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial/argument_parser/solution6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void run_program(std::filesystem::path & path, std::vector<uint8_t> sn, std::str

while (std::getline(file, line))
{
auto splitted_line = line | std::view::split('\t');
auto splitted_line = line | std::views::split('\t');
auto it = splitted_line.begin(); // move to 1rst column

if (std::find(sn.begin(), sn.end(), to_number<uint8_t>(*it)) != sn.end())
Expand Down
4 changes: 2 additions & 2 deletions doc/tutorial/pairwise_alignment/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Add the two sequences "ACGTGACTGACT" and "AGGTACGAGCGACACT" to the set and compu
of the four sequences and output the scores.

\hint
You can use the seqan3::view::pairwise_combine to generate all pairwise combinations.
You can use the seqan3::views::pairwise_combine to generate all pairwise combinations.
\endhint
\endassignment
\solution
Expand Down Expand Up @@ -319,7 +319,7 @@ Compute all pairwise alignments from the assignment 1 (only the scores). Only al
filter all alignments with 6 or less errors.

\hint
You can use the std::view::filter to get only those alignments that fit the requirements.
You can use the std::views::filter to get only those alignments that fit the requirements.
\endhint

\endassignment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <seqan3/alignment/pairwise/align_pairwise.hpp>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/range/view/pairwise_combine.hpp>
#include <seqan3/range/views/pairwise_combine.hpp>

using namespace seqan3;

Expand All @@ -20,6 +20,6 @@ int main()
auto config = align_cfg::mode{global_alignment} |
align_cfg::scoring{nucleotide_scoring_scheme{}};

for (auto const & res : align_pairwise(view::pairwise_combine(vec), config))
for (auto const & res : align_pairwise(views::pairwise_combine(vec), config))
debug_stream << "Score: " << res.score() << '\n';
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <seqan3/alignment/pairwise/align_pairwise.hpp>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/range/view/pairwise_combine.hpp>
#include <seqan3/range/views/pairwise_combine.hpp>

using namespace seqan3;

Expand All @@ -21,6 +21,6 @@ int main()
align_cfg::scoring{nucleotide_scoring_scheme{}} |
align_cfg::aligned_ends{free_ends_first};

for (auto const & res : align_pairwise(view::pairwise_combine(vec), config))
for (auto const & res : align_pairwise(views::pairwise_combine(vec), config))
debug_stream << "Score: " << res.score() << '\n';
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <seqan3/alignment/scoring/nucleotide_scoring_scheme.hpp>
#include <seqan3/alphabet/nucleotide/dna4.hpp>
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/range/view/pairwise_combine.hpp>
#include <seqan3/range/views/pairwise_combine.hpp>
#include <seqan3/std/ranges>

using namespace seqan3;
Expand All @@ -22,9 +22,9 @@ int main()
align_cfg::max_error{7u} |
align_cfg::result{with_score};

auto filter_v = std::view::filter([](auto && res) { return res.score() >= -6;});
auto filter_v = std::views::filter([](auto && res) { return res.score() >= -6;});

for (auto const & res : align_pairwise(view::pairwise_combine(vec), config) | view::persist | filter_v)
for (auto const & res : align_pairwise(views::pairwise_combine(vec), config) | views::persist | filter_v)
{
debug_stream << "Score: " << res.score() << '\n';
}
Expand Down
Loading

0 comments on commit 8c65076

Please sign in to comment.