Skip to content

Instantly share code, notes, and snippets.

@AlexBolotsin
Created July 20, 2017 18:49
Show Gist options
  • Save AlexBolotsin/fe493bc38406533dfe698937b3c8a432 to your computer and use it in GitHub Desktop.
Save AlexBolotsin/fe493bc38406533dfe698937b3c8a432 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
//#include <string_view>
constexpr long operator"" _KB(unsigned long long int value) { return value * 1024; }
long operator"" _MB(unsigned long long int value) { return value * 1024 * 1024; }
long operator"" _GB(unsigned long long int value) { return value * 1024 * 1024 * 1024; }
class A
{
public:
A(std::string str) { std::cout << "A(string) called\n"; }
//A(std::string_view str) { std::cout << "A(string_view) called\n"; }
A(const char* str) { std::cout << "A(const char*) called\n"; }
};
int main(int argc, char** argv)
{
//using namespace std::literals;
using namespace std::string_literals;
std::cout << "5 KB is " << 5_KB << " 7 MB is " << 7_MB << " 2 GB is " << 2_GB << "\n";
A a("whats up\n");
A b("whats up\n"s);
//A c("whats up\n"sv);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment