Maximal Munch


Beginners in C++ template programming commonly end up writing following kind of code, which is not understood by compilers.



// Following gives compilation errors:
std::vector
<std::vector<int>> vecOfVecOfInt;

// Corrected code – observe space betwen two consecutive “>”s.
std::vector<std::vector<int> > vecOfVecOfInt;


Due to “maximal munch” rule of compiler, the token “>>” is read as right-shift operator. Therefore, in nested templates in above example “>>” is not parsed as desired by the programmer. As a solution, programmer need to put a space between two consecutive “>”s.
Maximal Munch Maximal Munch Reviewed by Sourabh Soni on Sunday, January 31, 2010 Rating: 5

No comments

Author Details

Image Link [https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZYEKEHJPev0oC4dyp_vZFA3Q6PM99sbRGRgel5lr3s9PJPKQORaMDhc5f0wLqZjHSE79OnUom2STt1asn17AKrN2FPD6gH6gjz4sCmL-fCfCp5ksFbAT6sqxx02KLzi2C_Q2kSMTtQhIM/s1600/sourabhdots3.jpg] Author Name [Sourabh Soni] Author Description [Technocrat, Problem Solver, Corporate Entrepreneur, Adventure Enthusiast] Facebook Username [sourabh.soni.587] Twitter Username [sourabhs271] GPlus Username [#] Pinterest Username [#] Instagram Username [#] LinkedIn Username [sonisourabh] Youtube Username [sonisourabh] NatGeo Username [271730]