|
From: Patrick H. <pat...@gm...> - 2010-03-03 14:02:49
|
Carsten Neumann wrote:
> Hello,
>
> Attribute has (among others) the following c'tor:
>
> template <class T>
> Attribute(const T& val);
>
> and an output operator:
>
> std::ostream& operator<<(std::ostream& os, const Attribute& att);
>
> together these two constructs will grab any type that does not have a
> operator<< overload of its own and turn it into an infinite recursion at
> runtime (because the above c'tor uses setValue<T>(val) which uses a
> std::ostringstream to convert val into a string representation.
> One possible solution is to make the c'tor template explicit - this has
> the downside that the following needs to be adjusted though:
>
> element->setAttribute("att1", 1);
> element->setAttribute("att2", "something");
>
> to:
>
> element->setAttribute("att1", Attribute(1));
> element->setAttribute("att2", Attribute("something"));
>
> One way to retain the convenience would be to introduce:
>
> template <class T>
> Element::setAttribute(const std::string& attName, const T& attVal)
> {
> setAttribute(attName, Attribute(attVal));
> }
>
> Comments? I can create a patch along these lines if desired.
This sounds good to me. I think that we ran into this problem once quite a
while ago but never identified the source of the problems. Thanks for
looking into it.
-Patrick
--
Patrick L. Hartling
Senior Software Engineer, Priority 5
http://www.priority5.com/
|