Click here to Skip to main content
12,352,777 members (55,508 online)
Click here to Skip to main content

Tagged as

Stats

29.2K views
314 downloads
38 bookmarked
Posted

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...

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