3 ms·
If you want to iterate over the whole thing you can just use a fold expression, which arguably look cleaner than the non-compiletime ways to map over a collecti
by logicchains 2y ago
If you want to iterate over the whole thing you can just use a fold expression, which arguably look cleaner than the non-compiletime ways to map over a collection like std::transform.
- a_t48 2y agoEven with fold expressions, sometimes you need the actual index. See here https://github.com/basis-robotics/basis/blob/ca70aee6daca37ccb3997db56923adc1601ed455/cpp/unit/include/basis/unit.h#L230 https://github.com/basis-robotics/basis/blob/ca70aee6daca37c... - I did use a fold expression, but I needed the actual index in the fold expression to both do array access and to pass down into a template parameter.
- almostgotcaught 2y agoBro fold expressions are great and all but Jesus Christ the name spacing in that file. Like have you ever heard of this hidden C++ feature called `using namespace`?
- a_t48 2y agoYes, and? It's much easier to remove namespaces later using `using namespaces` if it really becomes a maintenance hazard than to go through and add them all back. This is library code that was intended to be included with unknown customer code, part of the goal is to avoid namespace collisions. (The `basis::` prefixes should go, though, the entire file is inside `basis`)
- almostgotcaught 2y ago> It's much easier to remove namespaces later using `using namespaces` lol how? sed? that's not a "much easier", that's a hack. it's actually much easier to remove `using namespace` because then the compiler will catch resolution errors. i actually didn't notice this was a header in which ok fine don't use `using namespace` but still this is java EE levels of boiler plate you've got going on; void SetupInput(const basis::UnitInitializeOptions &options, basis::core::transport::TransportManager *transport_manager, basis::core::containers::SubscriberQueueSharedPtr &subscriber_queue, basis::core::threading::ThreadPool *thread_pool, const std::unordered_map<std::string, std::string> &templated_topic_to_runtime_topic) { this signature is 90% namespace resolution - i have to squint to actually find the types...
- a_t48 2y agoLook I agree, it could be more readable. :)
- foota 2y agoArguably is doing a lot of work here, peoples eyes tend to start glazing over when I tell them it's a parameter pack fold :) I'd much rather have a loop that doesn't confuse people not familiar with the syntax.