Lumiera  0.pre.03
»edit your freedom«
can_lexical2string< X > Struct Template Reference

#include "lib/meta/trait.hpp"

Description

template<typename X>
struct lib::meta::can_lexical2string< X >

types able to be lexically converted to string representation

Note
this compile-time trait can't predict if such an conversion to string will be successful at runtime; indeed it may throw, so you should additionally guard the invocation with try-catch!
Remarks
this template is relevant for guarding lexical_cast<..> expressions. Such an expression won't even compile for some types, because of missing or ambiguous output operator(s). Ideally, there would be some automatic detection (relying on the existence of an operator<< for the given type. But at my first attempt in 2009 (commit 1533e5bd0) I couldn't make this work, so I fell back on just declaring all classes of types which are known to work with lexical_cast to string.
Meanwhile (2016) I think this is an adequate and robust solution and here to stay. Based on this, I'll add a generic overload for the output stream inserter operator<< to use custom string conversions; this trait is essential to exclude types which can be printed as-is.

Definition at line 368 of file trait.hpp.

+ Inheritance diagram for can_lexical2string< X >:
+ Collaboration diagram for can_lexical2string< X >:

The documentation for this struct was generated from the following file: