Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version

Application of C++11 User-Defined Literals to Handling Scientific Quantities, Number Representation and String Manipulation

, 1 Sep 2012 CPOL
keywords: user-defined literals , templates, constant expressions, recursive functions
#include <iostream>
#include <iomanip>
#include <string>

std::string operator "" _UP(const char* s, std::size_t n) 
{     
    std::string str(s,n);
    for (char &c: str)
    {       
       c = toupper(c);
    }
    return str;
}

int main()
{
    std::cout << "apple"_UP << std::endl;
    std::cout << ("APPLE" == "apple"_UP) << std::endl;    
    return 0;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Mikhail Semenov
Software Developer (Senior)
United Kingdom United Kingdom
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141216.1 | Last Updated 1 Sep 2012
Article Copyright 2012 by Mikhail Semenov
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid