1. boost::noncopyable
位于<boost/noncopyable.hpp>
中
2. BOOST_BINARY宏
位于<boost/utility/binary.hpp>
中
3. BOOST_CURRENT_FUNCTION宏
位于<boost/current_function.hpp>
中
与其类似的还有
__FILE__ //所在文件
__LINE__ //所在行号
__FUNCITON__ //所在函数
4. 用法示例
#include <boost/noncopyable.hpp>
#include <boost/utility/binary.hpp>
#include <boost/current_function.hpp>
#include <iostream>
using namespace std;
/*
class noncopyable
{
public:
noncopyable() = default;
~noncopyable() = default;
private:
noncopyable(const noncopyable &other);
noncopyable& operator=(const noncopyable &other);
};
*/
class A:public boost::noncopyable
{
public:
int a;
};
int main()
{
A a;
a.a = 13;
cout << a.a << endl;
//A b(a);
//cout << b.a << endl;
auto i=BOOST_BINARY(0101);
cout << i << endl;
cout << __FILE__ << __LINE__ << endl;
cout << __FUNCTION__ << endl;
cout << BOOST_CURRENT_FUNCTION << endl;
}
5. std::bitset类型
#include <bitset>
#include <iostream>
using namespace std;
void bitset_test()
{
bitset<5> b(5); //用unsigned值初始化
cout << b << endl;
bitset<3> b2("010"); //用string初始化
cout << b2 << endl;
cout << b2.count() << endl; //b.count():b中置位的位数(即1的个数)
b2.flip(); //翻转所有位
cout << b2 << endl;
cout << b2.count() << endl;
b.reset(); //将所有位复位(即设为0)
cout << b << endl;
b.set(); //将所有位置位(即设为1)
cout << b << endl;
unsigned long l = b.to_ulong(); //提取b的值,转换为unsigned long, to_ulong()
cout << l << endl;
string s = b.to_string(); //提取b的值,转化为string
cout << s << endl;
}
输出结果为: