cpp home

https://en.cppreference.com/w/

 

 

 

The zero-overhead principle is a C++ design principle that states:

  1. You don't pay for what you don't use.
  2. What you do use is just as efficient as what you could reasonably write by hand.

In general, this means that no feature should be added to C++ that would impose any overhead, whether in time or space, greater than a programmer would introduce without using the feature.

The only two features in the language that do not follow the zero-overhead principle are runtime type identification and exceptions, and are why most compilers include a switch to turn them off.

 

 

#include <string>
using namespace std;

int  f(unsigned long long d){
    return 1;
}
//int  f( long long d){
//    return 1;
//}


int fs(const string& p, char *o){
    return p == o;
}

int cmain(int argc, char *argv[])
{
    char e[]="efawse";
    auto z=fs("efawse", e);
    int k=9;
    k=f(k);

    return 0;
}


#include "tuple.h"


struct E{
    struct D{
        void f(E *e){
            return z(e);
        }
        void z(E *e){
            e->f();
        }
    };

private:
    void f(){

    }
};


#include <iostream>
using std::cout;

typedef void (*TestFuncType)(void);
#include <string>
#include <list>

typedef std::string String;

int smain(int argc, char *argv[])
{
    E e;
    E::D d;
    d.f(&e);
    int k=9;
    Tuple<int, char> m (k, '7');
    return 0;
}



struct A{
    A(){

    }
//    A(const A&){
//cout<<"A&\n";
//    }
//    A(A&&){
//cout<<"A&&\n";
//    }
     const char * p;
};

struct B{
    B(){

    }
//    B(const B&){
//cout<<"B&\n";
//    }
//    B(B&&){
//        cout<<"B&&\n";
//    }
};


struct C{
    A a;
    B b;
};



int main(int argc, char *argv[])
{
//    A a ;
//    a.p = 98;
//    A b = a;
    C c;
    c.a.p = "efs";
    cout << "see\n";
    C e((C&&)c);
    cout << "end\n";
    return 0;
}

posted @ 2020-06-30 13:46  zJanly  阅读(154)  评论(0)    收藏  举报