C++ 标准库读书杂记四

1.命名空间

std::cout<<

using std::cout;
cout <<

using namespace std;
cout<<

2.error and exception

base class :exception //<exception>

exception list:

bad_cast //dynamic_cast()

bad_typeid //typeid

bad_exception //unexpacted

invalid_argument 

length_error

future_error

range_error

overflow_error

underflow_error

bad_alloc

bad_weak_ptr

bad_function_call

涉及到的头文件:<exception>、<stdexcept>、<system_error>、<new>、<ios>、<future>、<typeinfo>、<>、<>、<>

异常类成员:接口 what();差错码、差错状态

exception_ptr 传递异常

void foo()
{ 
	try
	{
		throw ...;
	}
	catch (...)
	{
		eptr = std::current_exception();
		
	}
}
//用于线程间传递
void bar()
{
    if (eptr != nullptr)
    {
        std::rethrow_exception(eptr);// 重新抛出这个异常
    }
}

3.Callable Object(可调用对象)

函数

函数指针

lambda//就是个不具名的函数

std::bind(*func,arge[0]...);

std::async(*func,arge[0]...);

class std::function<>

4.并发与多线程

thread_local //定义线程特定对象和变量

防止标准库引用的造成的冲突:指定为sharable without data races 、locking机制

并发只读访问,原子操作都是同步的。

default allocator

猜你喜欢

转载自blog.csdn.net/u012516571/article/details/82229240