Boost logo

Boost :

Subject: [boost] [poly_collection] throws upon insertion
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2017-05-08 14:55:36


Hi,
I am looking at the documentation of poly_collection. I will not be able to
thoroughly review and test the library. But judging from the documentation,
the problem is worth solving, and the approach to solve it is sound.

I have one question/observation though. I am trying to figure out how
preventing an incorrect insert() works. In the docs (
http://rawgit.com/joaquintides/poly_collection/website/doc/html/poly_collection/tutorial.html#poly_collection.tutorial.deeper_into_the_segmented_nature.type_registration)

it says that it will sometimes throw if it cannot determine the most
derived type.

In the class reference, I get:
(
http://rawgit.com/joaquintides/poly_collection/website/doc/html/poly_collection/reference.html#poly_collection.reference.polymorphic_containers.polymorphic_collections.modifiers
)

```
(1) c.insert(x)
(2) c.insert(it,x)

Effects: If the type of the subobject of t is not registered, then if this
type is T and T is acceptable, does the registration, otherwise throws. If
t is not a non-const rvalue expression and the type of its subobject is not
CopyConstructible, throws. Inserts an element with a subobject move
constructed or copy constructed from the subobject of t: (1) at the end of
the corresponding segment; (2) just before the position indicated by it, if
it points to the corresponding segment, or at the end of the segment
otherwise.

Returns: An iterator to the newly inserted element.

Complexity: Amortized constant time plus linear in the distance from the
insertion position to the end of the segment.
```

And maybe it is just me, but I cannot make the sense of it. First, it
refers to 't' but in the signatures we have an 'x'. Next, the first
sentence has two "if"s and one "otherwise" and I do not know which "if" the
"otherwise" binds to. I read it as saying: if T is derived from the
interface (like class `warrior`) but is not movable (which implies that T
is not "acceptable"), then the program will compile fine but will later
throw an exception. Is my interpretation correct? But if so, why not refuse
to compile instead?

Maybe it would be better tom make the prose longer in "Effects" clause, but
to make it harder for misinterpretation.

Regards,
&rzej;


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk