zoukankan      html  css  js  c++  java
  • 【算法随笔】写一个自己的名词空间

    C++比C多了很多实用的东西,像class类,使得C++能够更好的OOP,struct也有了构造函数等等。还有一个东西是名词空间。想必大多数人不会对下面这句话陌生:

    using namespace std;

    也就是引用了名词空间std(standard)。

    看上去很高大上对不对?其实名词空间也不难写出。如下面的实例:

    1 namespace  myfunc{
    2     void swap(int &a,int &b){
    3         a^=b,b^=a,a^=b;
    4 }
    5   #define IGNB 1<<31
    6 }

    其实和写了一个头文件差不多

    下面公布我自己的名词空间:

     1 namespace Jason{
     2     inline void scan(int &x){
     3     int f=1;x=0;char s=getchar();
     4     while(s<'0' || s>'9'){if(s=='-') f=-1;s=getchar();}
     5     while(s>='0' && s<='9'){x=x*10+s-'0';s=getchar();}
     6     x*=f;
     7 }
     8     inline void print(int x){
     9         if(x<0){putchar('-');x=-x;}
    10         if(x>9)print(x/10);char s=x%10+'0';
    11         putchar(s);
    12     }
    13 struct Edge_B{
    14     int to,dis;
    15     Edge_B* nxt;
    16 Edge_B(int to=-1,int dis=-1,Edge_B* n=NULL){this->to=to,this->dis=dis,this->nxt=n;} 
    17 };
    18 }

    使用时加一句using namespace Jason;就OK了(内部已经定义了读入输出优化)。

    //更新于2019/1/25

    更新了mymemset。

    1 template<typename value>
    2 void* mymemset(void* __BASE,valve __val,unsigned ___SIZE)
    3 {
    4     if(__BASE==NULL || ___SIZE<0 )return NULL;
    5     char* __PT=__BASE;
    6     while(___SIZE--)*++__PT=val;
    7     return __BASE;
    8 }

     这个是真正的声明[笑cry]

  • 相关阅读:
    收藏夹
    获取某个元素在页面上的偏移量
    React多行文本溢出处理(仅针对纯文本)
    react
    CDN初学搭建(ats)
    linux查看cpu、内存、版本信息
    MySQL5.6版本性能调优my.cnf详解
    How to install cacti on centos 6
    win10安装.net3.5 报错解决
    CentOS6.5安装Cacti统计图乱码解决
  • 原文地址:https://www.cnblogs.com/JasonY1337357025/p/10299652.html
Copyright © 2011-2022 走看看