mesos-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joris Van Remoortere <joris.van.remoort...@gmail.com>
Subject Re: Review Request 46425: Add helper function to simplify tokenize handling.
Date Wed, 14 Dec 2016 22:35:28 GMT

-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/46425/#review159240
-----------------------------------------------------------




3rdparty/stout/include/stout/strings.hpp (lines 170 - 175)
<https://reviews.apache.org/r/46425/#comment230184>

    What do you think about introducing a building block version of this function like:
    ```
    void foreachtoken(
        const std::string& s,
        const std::string& delims,
        const lambda::function<bool (const std::string&)& callback);
    ```
    
    I think it is a common pattern to provide a return type of `bool` in a callback like this.
The reason is that other transforms can be composed on top.
    
    Then we can write:
    ```
    void foreachtoken(
        const std::string& s,
        const std::string& delims,
        const lambda::function<void (const std::string&)& callback,
        const Option<size_t>& max_tokens = None()) {
        size_t count = 0;
        foreachtoken(s, delims, [&](const string& token) -> bool {
          if (max_tokens.isSome() && count >= max_tokens.get()) { return false;
}
          callback(token);
          ++count;
          return true;
        });
    }
    ```
    
    I would also consider making `max_tokens` be a template parameter as from our code base
it seems we are never interested in a dynamic value. This may be going too far though and
is just food for thought for a future discussion.
    
    What do you think?



3rdparty/stout/include/stout/strings.hpp (line 178)
<https://reviews.apache.org/r/46425/#comment230185>

    Please do capture the callback by `const &` when implementing this pattern.
    
    The rule to follow is:
    -If the lambda will be fully consumed during the lifetime of the function, then it is
safe to capture by `const &`.
    -If the lambda will be invoked later, the code responsible for capturing the lambda to
execute asynchronously should make the copy.


- Joris Van Remoortere


On June 29, 2016, 4:56 p.m., Klaus Ma wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/46425/
> -----------------------------------------------------------
> 
> (Updated June 29, 2016, 4:56 p.m.)
> 
> 
> Review request for mesos, Benjamin Mahler and Joris Van Remoortere.
> 
> 
> Bugs: MESOS-5234
>     https://issues.apache.org/jira/browse/MESOS-5234
> 
> 
> Repository: mesos
> 
> 
> Description
> -------
> 
> Add helper function to simplify tokenize handling.
> 
> 
> Diffs
> -----
> 
>   3rdparty/stout/include/stout/strings.hpp 162bdfb6c4f5a6b108761ebccd9b77e672f6dd87 
>   3rdparty/stout/tests/strings_tests.cpp b54a9dbf162403310b8bba687442e184a473f5a6 
> 
> Diff: https://reviews.apache.org/r/46425/diff/
> 
> 
> Testing
> -------
> 
> make && make check
> 
> 
> Thanks,
> 
> Klaus Ma
> 
>


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message