Previous section   Next section

Imperfect C++ Practical Solutions for Real-Life Programming
By Matthew Wilson
Table of Contents
Chapter 25.  Fast, Non-intrusive String Concatenation


25.5. Pathological Bracing

You might think you've spotted a flaw in the technique, whereby unnecessary, but perfectly legal, bracing could break the technique, or at least render it ineffective. In the following code, the application of the parentheses has reversed the order of evaluation.



String s = s1 + (" " + (s2 + (" " + s3)));



Although such things would likely only occur as a result of some helpful soul trying to demonstrate that fast concatenation could be broken, it's already been dealt with. We have more overloads to cope with all cases:

Listing 25.6.


template < . . . >


fast_string_concatenator<S, C, T>


  operator +(fsc_seed const &, fast_. . .< > const &);


. . .


  operator +(fast_. . .< > const &, fast_. . .< > const &);


. . .


  operator +(S const &, fast_. . .< > const &);


. . .


  operator +(C const *, fast_. . .< > const &);


. . .


  operator +(C const &, fast_. . .< > const &);



and the corresponding constructors in the class:



  fast_. . . (class_type const &lhs, class_type const &rhs);


  fast_. . . (string_type const &lhs, class_type const &rhs);


  fast_. . . (char_type const *lhs, class_type const &rhs);


  fast_. . . (char_type const lhs, class_type const &rhs);



The interesting thing about the use of this bracing is that not only can it not break the legality of the code but, just as with seeding, it scarcely affects performance.[6]

[6] Full results for both seeding and pathological bracing are included on the CD.


      Previous section   Next section