Comments (8)
I forgot to fill more details. it
is the value returned from obj.key_begin()
and obj
is dynamic::variable
from trial.protocol.
Good catch.
The resolution gives me some headache though. There are two solutions we can use:
- Add a
key_iterator erase(key_iterator)
member function. - Add an explicit conversion from
key_iterator
toconst_iterator
, e.g.key_iterator::base() -> const_iterator
.
The first solution enables the user to loop over all elements and erase some of them. That is:
for (auto it = v.key_iterator(); it != v.key_end(); /* increment done below */)
{
if (should_we_erase_element(*it))
it = v.erase(it); // erase returns a key_iterator
else
++it;
}
The second solution has the advantage of being more general, so it can be used for other functions, like insert()
. However, the example above cannot be used.
I am leaning towards the second solution because:
- We already have the looping problem with
iterator erase(const_iterator)
which was introduced in C++11 (via proposal N2350.) - There is precedence for the explicit iterator conversion with
reverse_iterator::base()
.
from trial.protocol.
Why can't the example compile with solution #2
?
from trial.protocol.
Because it
has type key_iterator
and erase
returns type iterator
.
There is no conversion from iterator
to key_iterator
because the latter needs an extra member variable.
from trial.protocol.
Regarding your comment about parsing the entire input to a dynamic::variable
, you will be pleased to know that I am working on a json::parse
and json::format
that works on dynamic::variable
without the need for Boost.Serialization.
from trial.protocol.
We already have the looping problem with iterator erase(const_iterator) which was introduced in C++11 (via proposal N2350.)
Okay. I've read N2350 (except for the proposed wording chapter).
I think if we apply the same solution here, the proper solution would be to add key_erase
to match the begin
/key_begin
split. key_erase
would receive a const_key_iterator
and return a key_iterator
.
I wouldn't mind to have a overloaded erase
function instead typing the key_
thou.
Regarding your comment about parsing the entire input to a
dynamic::variable
, you will be pleased to know that I am working on ajson::parse
andjson::format
that works ondynamic::variable
without the need for Boost.Serialization.
Surely I'll enjoy that.
from trial.protocol.
I have added a key_iterator::base()
function to convert a key_iterator into a const_iterator in db775c4, so now v.erase(kit.base())
is doable.
Regarding the key_erase()
function, I would rather have such functionality as algorithms, e.g. like the dynamic::key::count()
and dynamic::key::find()
algorithms, to prevent a proliferation of the variable
interface.
from trial.protocol.
Okay. Let's leave the issue open for some time in case others want to pop in and add their comments.
I have added a
key_iterator::base()
function to convert a key_iterator into a const_iterator in db775c4, so nowv.erase(kit.base())
is doable.
This will suit me for now. Probably I'll send a PR in the following weeks with one dynamic::key::erase
. The question of a sweet spot here between convenience and a clean interface is a tricky one. Not many ready guidelines we can adhere to. But also, it's the problems we always face with novel design (otherwise they wouldn't be novel).
from trial.protocol.
Related Issues (20)
- Change Allocator template to Allocator type HOT 1
- AllocatorAwareContainer HOT 4
- Use to_address() HOT 2
- Do not inherit from allocator HOT 1
- Use error specializations thoroughly HOT 1
- Compare current string-value with a string_view w/o allocating HOT 12
- reader.value<std::string>() should allow the allocator to be provided HOT 5
- String collector API should only be noexcept if `Collector()` is noexcept HOT 11
- Parser gets confused on non-NULL terminated string HOT 1
- Isn't boost::serialization::nvp missing in serialization support? HOT 1
- Literal whitespace vs literal node HOT 7
- Split symbol::string and symbol::object_key events HOT 3
- Tests fail to build on boost 1.76 HOT 6
- Reader algorithms on chunk_reader HOT 4
- Parsers combinators HOT 7
- Merged matching & decode on Boost.Hana serialization
- Use asciidoc to document new pages HOT 4
- fails to build with latest visual studio
- Issues with constness in std::make_pair HOT 4
- Generator for real numbers shouldn't print the fractional part if there is none HOT 3
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 trial.protocol.