simonask / rx-ranges Goto Github PK
View Code? Open in Web Editor NEWrx::ranges is a minimalist ranges library for C++17
License: MIT License
rx::ranges is a minimalist ranges library for C++17
License: MIT License
Hello.
I have some preliminary implementation split range, strip transform and join sink. But I'm not sure if they should be part of main lib or should be placed in a separate file as an optional extension.
strip takes two const iterators of input, two const iterators of separator and produces basic_string_view as output.
strip takes range of const CharT*, basic_string_view or basic_string as input and produces basic_string_view as output.
join takes range of const CharT*, basic_string_view or basic_string and const CharT*, basic_string_view or basic_string as input and produces basic_string as output.
Need to discuss this and I'll make corresponding PR.
As in the title, code below doesn't compile without calling to_vector() after sort
std::vector<int> vec { 1, 2, 3, 4, 5 };
auto firstItem = vec
| rx::sort()
| rx::first();
Currently, many functions are marked noexcept
, despite potentially calling user-provided functions that may throw. The right thing to do is to add noexcept(noexcept(...))
syntax in those places.
The drawback is that it uglifies the code pretty significantly.
There are also probably places where unconditional noexcept
can be safely added.
I would expect it to work like
RX_OPTIONAL<output_type> last_value;
uniq(…) {
last_value.emplace(input.get());
input.next();
}
constexpr void next() {
while (!input.at_end()) {
auto&& next_value = input.get();
input.next();
if (!eq(*last_value, next_value)) {
last_value.emplace(std::forward<decltype(next_value)>(next_value));
return;
}
}
last_value.reset();
}
constexpr output_type get() const {
return last_value;
}
Hi!
Here dead simple example code:
#include <stdio.h>
#include <vector>
#include <rx/ranges.hpp>
int main()
{
using namespace std;
using namespace rx;
vector<int> v = {1,2,3,4,5,6};
auto r = v | rx::transform([](auto i){printf("tr=%d\n", i);return i*2;}) | filter([](auto i){return i>6;});
for(auto i : r) {
printf("for=%d\n", i);
}
}
I noticed that once filter condition is true, tr= is printed twice for each for= output. IMO it's not really expected behaviour and looks like overhead.
As in the title. Not sure if can be marked as bug, but at least it's worth mentioning in the requirements.
Example Code and Console Output
#include "pch.h"
#include "ranges.hpp"
#include <iostream>
#include <vector>
template <typename Type>
struct Point {
Point(Type x, Type y) noexcept
: X { x }
, Y { y }
{
}
Type X;
Type Y;
};
int main()
{
std::vector<Point<int>> vec;
vec.emplace_back(1, 2);
vec.emplace_back(2, 3);
vec.emplace_back(3, 4);
auto transformed = vec
| rx::filter([](Point<int> point) { return point.X == 3; })
| rx::transform([](Point<int> point) { return point.X; })
| rx::to_vector();
for (auto x : transformed) {
std::cout << x << '\n';
}
}
1>c:\users\tomek\source\repos\consoleapplication7\consoleapplication7\ranges.hpp(1476): error C2133: 'vec': unknown size
1>c:\users\tomek\source\repos\consoleapplication7\consoleapplication7\ranges.hpp(235): note: see reference to function template instantiation 'auto rx::to_vector::operator ()<LHS>(R &&) const' being compiled
1> with
1> [
1> LHS=rx::transform<main::<lambda_5eaf32db83d37af66b6c17510f1a5e05>>::Range<Inner>,
1> R=rx::transform<main::<lambda_5eaf32db83d37af66b6c17510f1a5e05>>::Range<Inner>
1> ]
1>c:\users\tomek\source\repos\consoleapplication7\consoleapplication7\ranges.hpp(1476): error C2512: 'std::vector<remove_cv<remove_reference<remove_cv<_Ty>::type::output_type>::type>::type,std::allocator<remove_cv<remove_reference<remove_cv<_Ty>::type::output_type>::type>::type>>': no appropriate default constructor available
1> with
1> [
1> _Ty=remove_reference<unknown-type>::type
1> ]
1>c:\users\tomek\source\repos\consoleapplication7\consoleapplication7\ranges.hpp(1476): note: see declaration of 'std::vector<remove_cv<remove_reference<remove_cv<_Ty>::type::output_type>::type>::type,std::allocator<remove_cv<remove_reference<remove_cv<_Ty>::type::output_type>::type>::type>>'
1> with
1> [
1> _Ty=remove_reference<unknown-type>::type
1> ]
1>c:\users\tomek\source\repos\consoleapplication7\consoleapplication7\ranges.hpp(1477): fatal error C1903: unable to recover from previous error(s); stopping compilation
Currently, many things are marked constexpr
that may or may not actually be usable in constexpr
contexts due to the use of assertions. Whether assert()
is usable in a constexpr
context seems compiler-dependent.
Here is a solution for implementing assertions in constexpr
contexts: https://akrzemi1.wordpress.com/2017/05/18/asserts-in-constexpr-functions/
Discussion: ec88755#r36088781
But basically changing the definition of s_months_names
to be constexpr
and avoid the runtime cost.
https://github.com/simonask/rx-ranges/blob/develop/include/rx/ranges.hpp#L2053
_get
should not call itself if sizeof...(rest) == 0
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.