1efbfdb0cSShuo Chen#pragma once 2d47c0202SShuo Chen#include <string> 3efbfdb0cSShuo Chen 424ca08a8SShuo Chen#include <string.h> // memset 524ca08a8SShuo Chen 624ca08a8SShuo Cheninline void memZero(void* p, size_t n) 724ca08a8SShuo Chen{ 824ca08a8SShuo Chen memset(p, 0, n); 924ca08a8SShuo Chen} 1024ca08a8SShuo Chen 11efbfdb0cSShuo Chenclass noncopyable 12efbfdb0cSShuo Chen{ 13efbfdb0cSShuo Chen protected: 14efbfdb0cSShuo Chen noncopyable() {} 15efbfdb0cSShuo Chen 16efbfdb0cSShuo Chen private: 17efbfdb0cSShuo Chen noncopyable(const noncopyable&) = delete; 18efbfdb0cSShuo Chen void operator=(const noncopyable&) = delete; 19efbfdb0cSShuo Chen}; 20efbfdb0cSShuo Chen 21efbfdb0cSShuo Chenstruct copyable 22efbfdb0cSShuo Chen{ 23efbfdb0cSShuo Chen}; 24efbfdb0cSShuo Chen 251dfcf3a2SShuo Chen// For passing C-style string argument to a function. 261dfcf3a2SShuo Chenclass StringArg : copyable 27efbfdb0cSShuo Chen{ 28efbfdb0cSShuo Chen public: 291dfcf3a2SShuo Chen StringArg(const char* str) 301dfcf3a2SShuo Chen : str_(str) 311dfcf3a2SShuo Chen { } 321dfcf3a2SShuo Chen 331dfcf3a2SShuo Chen StringArg(const std::string& str) 341dfcf3a2SShuo Chen : str_(str.c_str()) 351dfcf3a2SShuo Chen { } 361dfcf3a2SShuo Chen 371dfcf3a2SShuo Chen const char* c_str() const { return str_; } 381dfcf3a2SShuo Chen 39efbfdb0cSShuo Chen private: 401dfcf3a2SShuo Chen const char* str_; 41efbfdb0cSShuo Chen}; 42efbfdb0cSShuo Chen 43efbfdb0cSShuo Chentemplate<typename To, typename From> 448d51ab70SShuo Cheninline To implicit_cast(From f) 45355c2bf7SShuo Chen{ 46355c2bf7SShuo Chen return f; 47efbfdb0cSShuo Chen} 48