Comments (7)
Test code have written to check the feature
TEST_CASE( "CollectAssociative" )
{
ureact::context ctx;
auto src = ureact::make_source<std::pair<std::string, int>>( ctx );
auto src_tuple = ureact::transform(
src, []( const auto& pair ) { return std::make_tuple( pair.first, pair.second ); } );
ureact::signal<std::map<std::string, int>> collected_map;
ureact::signal<std::map<std::string, int>> collected_map_2;
SUBCASE( "Functional syntax" )
{
collected_map = ureact::collect<std::map>( src );
collected_map_2 = ureact::collect<std::map>( src_tuple );
}
SUBCASE( "Piped syntax" )
{
collected_map = src | ureact::collect<std::map>;
collected_map_2 = src_tuple | ureact::collect<std::map>;
}
src << std::pair( "A", 1 );
src << std::pair( "B", 2 );
src << std::pair( "C", 3 );
using namespace std::string_literals;
const auto expected = std::map{
std::pair( "A"s, 1 ),
std::pair( "B"s, 2 ),
std::pair( "C"s, 3 ),
};
CHECK_EQ( collected_map.get(), expected );
CHECK_EQ( collected_map_2.get(), expected );
}
from ureact.
std::to proposal https://open-std.org/jtc1/sc22/wg21/docs/papers/2022/p1206r7.pdf
auto l = std::views::iota(1, 10);
// create a vector with the elements of l
auto vec = ranges::to<std::vector<int>>(l); // or vector{std::from_range, l};
//Specify an allocator
auto b = ranges::to<std::vector<int, Alloc>>(l, alloc); // or vector{std::from_range, l, alloc};
//deducing value_type
auto c = ranges::to<std::vector>(l);
// explicit conversion int -> long
auto d = ranges::to<std::vector<long>>(l);
//Supports converting associative container to sequence containers
auto f = ranges::to<std::vector>(m);
//Supports converting sequence containers to associative ones
auto g = ranges::to<std::map>(f);
//Pipe syntaxe
auto g = l | ranges::view::take(42) | ranges::to<std::vector>();
//Pipe syntax with allocator
auto h = l | ranges::view::take(42) | ranges::to<std::vector>(alloc);
//The pipe syntax also support specifying the type and conversions
auto i = l | ranges::view::take(42) | ranges::to<std::vector<long>>();
// Nested ranges
std::list<std::forward_list<int>> lst = {{0, 1, 2, 3}, {4, 5, 6, 7}};
auto vec1 = ranges::to<std::vector<std::vector<int>>>(lst);
auto vec2 = ranges::to<std::vector<std::deque<double>>>(lst);
from ureact.
Some checks in the godbolt https://godbolt.org/z/jqePW8a7h. It seems that it is impossible to accept both concrete type and parameterized type at the same time if it is not an overloaded template function.
Optional passing of allocator is another can of worm I don't want to touch for now. The same with nested containers. It doesn't look practical for ureact anyway.
from ureact.
Update on godbolt https://godbolt.org/z/9hsvjfzfv.
from ureact.
Associative container support is added. But there is at least some ambiguity with std::map
: it has both .insert()
method that doesn't override previous values and operator[]
that does override. It is not clear which behavior is desired. For now operator[]
has bigger priority than .insert()
.
from ureact.
So, no allocator support for now and no passing of specific class for now (it require a new adaptor name like collect_in<std::vector>). I have no idea how to use allocators, so it's hard to make by me.
from ureact.
Closing for now. Reopen if further improvements are wanted
from ureact.
Related Issues (20)
- Rework observer/scoped_observer/observe/tap
- Consider adding `transaction::finish()` method HOT 1
- Consider to support iterators as an observer argument HOT 1
- Make sure transactions can't be started or finished when turn is in progress HOT 1
- `adjustment` adapter possible improvements
- Make `Adaptor` `AdaptorClosure` and nodes part of public interface
- Try to mesure and improve compile times HOT 8
- Get rid of `ureact_amalgamated.hpp` HOT 1
- Make normal library mode (not header-only)
- First code example in doc/introduction.adoc does not compile HOT 5
- Consider adding dereference operator for signals
- Consider `connection_owner` idea from `PG1003/observer`
- Research how to implement Qt style property bindings HOT 2
- Compile errors for Visual Studio HOT 4
- Get rid of `issue_template.md` HOT 1
- Rework github actions
- `ureact::merge` can't compile in latest MSVC in c++20 mode HOT 3
- Consider making "event_source::operator<<" transaction wrapper HOT 1
- Research signal-slot library features
- Consider pitchfork project structure (aka PFL)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ureact.