UI-Coordinates: need to spell out all ctors explicitly

the usual drill...
once there is one additional non explicit conversion ctor,
lots of preferred conversion paths are opened under various conditions.

The only remedy is to define all ctors explicitly, instead of letting the
compiler infer them (from the imported base class ctors). Because this way
we're able to indicate a yet-more-preferred initialisation path and thus
prevent the compiler from going the conversion route.

In the actual case, the coordinate Builder is the culprit; obviously
we need smooth implicit conversion from builder expressions, and obviously
we also want to restrict Builder's ctors to be used from UICoord solely.

Unfortunately this misleads the compiler to do implement a simple copy construction
from non const reference by going through the prohibited Builder ctor, or to
instantiate the vararg-ctor inherited from PathArray.

Thus better be explicit and noisy...
This commit is contained in:
Fischlurch 2017-10-02 22:15:12 +02:00
parent 5127414773
commit 42277c5760
2 changed files with 28 additions and 4 deletions

View file

@ -101,8 +101,8 @@ namespace interact {
/**
* Describe a location within the UI through structural/topological coordinates.
* A UICoord specification is a tuple, elaborating a path through the hierarchy
* of UI elements down to the specific element referred.
* A UICoord specification is a sequence of Literal tokens, elaborating a path descending
* through the hierarchy of UI elements down to the specific UI element to refer.
*
* @todo initial draft as of 9/2017
*/
@ -112,7 +112,26 @@ namespace interact {
using PathAry = lib::PathArray<UIC_INLINE_SIZE>;
public:
using PathAry::PathArray;
/**
* UI-Coordinates can be created explicitly by specifying a sequence of Literal tokens,
* which will be used to initialise and then normalise the underlying PathArray.
* @warning Literal means _"literal"_ with guaranteed storage during the whole execution.
* @remarks - in case you need to construct some part, then use Symbol to _intern_ the
* resulting string into the global static SymbolTable.
* - usually the Builder API leads to more readable definitions,
* explicitly indicating the meaning of the coordinate's parts.
*/
template<typename...ARGS>
explicit
UICoord (ARGS&& ...args) : PathArray(std::forward<ARGS> (args)...) { }
UICoord (UICoord&&) = default;
UICoord (UICoord const&) = default;
UICoord (UICoord& o) : UICoord((UICoord const&)o) { }
UICoord& operator= (UICoord const&) = default;
UICoord& operator= (UICoord &&) = default;
/* === Builder API === */

View file

@ -354,7 +354,12 @@ namespace test {
void
verify_comparisons()
{
UNIMPLEMENTED ("verify comparison of UI coordinates");
UICoord u1 {"Γ","Δ","Θ","Ξ","Σ","Ψ","Φ" };
UICoord u11{"Γ","Δ","Θ","Ξ","Σ","Ψ","Φ","Ω"};
UICoord u2 {"Γ","Δ","Θ","Σ","Ξ","Ψ","Φ","Ω"};
UICoord u1c{u1};
}