Click here to Skip to main content
13,351,985 members (76,959 online)
Click here to Skip to main content

Stats

35.6K views
338 downloads
38 bookmarked
Posted 27 Aug 2012

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

, 1 Sep 2012
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
Pro
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180111.1 | Last Updated 1 Sep 2012
Article Copyright 2012 by Mikhail Semenov
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid