zero cost abstractions

Zero cost abstraction does not mean that there is no cost to running the code, it means there would be no advantage to you hand writing what the compiler generates because the C++ abstractions are so efficient.

 

// zero-cost-abstractions.cpp : This file contains the 'main' function. Program execution begins and ends there. // #include <iostream> #include <string> using namespace std; void printString(string& msg) { cout << msg << endl; } enum days_of_week { mon, tue, wed, thur, fri, sat, sun }; int main() { const string s1 = "Hello world\n"; string s2 = s1; printString(const_cast<string&>(s1)); printString(s2); auto today = days_of_week{ tue }; days_of_week day = tue; days_of_week day2 = 3; std::cout << "Hello World!\n"; }