Click here to Skip to main content
12,882,397 members (26,910 online)
Click here to Skip to main content

Tagged as

Stats

32.1K views
38 bookmarked
Posted 27 Aug 2012

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

, 31 Aug 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

You may also be interested in...

Pro
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170422.1 | Last Updated 1 Sep 2012
Article Copyright 2012 by Mikhail Semenov
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid