草庐IT

make_pair

全部标签

c++ - std::make_shared() 是否使用自定义分配器?

考虑thiscode:#include#includeclassSomeClass{public:SomeClass(){std::coutptr1(newSomeClass);std::coutptr2(std::make_shared());std::cout这是它的输出:CustomnewSomeClass()Anotherone...SomeClass()Done!~SomeClass()~SomeClass()Customdelete显然,std::make_shared()没有调用new运算符——它使用的是自定义分配器。这是std::make_shared()的标准行为吗?

c++ - std::make_shared() 是否使用自定义分配器?

考虑thiscode:#include#includeclassSomeClass{public:SomeClass(){std::coutptr1(newSomeClass);std::coutptr2(std::make_shared());std::cout这是它的输出:CustomnewSomeClass()Anotherone...SomeClass()Done!~SomeClass()~SomeClass()Customdelete显然,std::make_shared()没有调用new运算符——它使用的是自定义分配器。这是std::make_shared()的标准行为吗?

c++ - STL 算法 : Why no additional interface for containers (additional to iterator pairs)?

我想知道为什么STL不会重载它们的算法函数,这样我就可以通过简单地提供一个容器而不是采用更冗长的方式来传递begin+end迭代器来调用它们。我当然理解为什么我们还想使用迭代器对来处理容器/数组的子序列,但是,几乎所有对这些方法的调用都使用了整个容器:std::for_each(myVector.begin(),myVector.end(),doSomething);我会发现只写更方便、可读和可维护std::for_each(myVector,doSomething);STL不提供这些重载是否有原因?[编辑:我的意思不是用这个受限的接口(interface)替换接口(interface

c++ - STL 算法 : Why no additional interface for containers (additional to iterator pairs)?

我想知道为什么STL不会重载它们的算法函数,这样我就可以通过简单地提供一个容器而不是采用更冗长的方式来传递begin+end迭代器来调用它们。我当然理解为什么我们还想使用迭代器对来处理容器/数组的子序列,但是,几乎所有对这些方法的调用都使用了整个容器:std::for_each(myVector.begin(),myVector.end(),doSomething);我会发现只写更方便、可读和可维护std::for_each(myVector,doSomething);STL不提供这些重载是否有原因?[编辑:我的意思不是用这个受限的接口(interface)替换接口(interface

c++ - 为什么 make_optional 会衰减它的参数类型?

(可能不是C++14,可能是LibraryTS)工具make_optional被定义(inn3672)为:templateconstexproptional::type>make_optional(T&&v){returnoptional::type>(std::forward(v));}为什么要转换类型T(即不只是返回optional),并且是否有使用decay的哲学(以及实际)理由具体作为转型? 最佳答案 decay的一般用途就是取一个类型,修改为适合存储。看看这些decay的例子工作,而remove_reference不会:a

c++ - 为什么 make_optional 会衰减它的参数类型?

(可能不是C++14,可能是LibraryTS)工具make_optional被定义(inn3672)为:templateconstexproptional::type>make_optional(T&&v){returnoptional::type>(std::forward(v));}为什么要转换类型T(即不只是返回optional),并且是否有使用decay的哲学(以及实际)理由具体作为转型? 最佳答案 decay的一般用途就是取一个类型,修改为适合存储。看看这些decay的例子工作,而remove_reference不会:a

c++ - 比较两个map::iterators:为什么需要std::pair的拷贝构造函数?

下面非常简单的代码在C++98中编译和链接时不会出现警告,但在C++11模式下会出现难以理解的编译错误。#includestructA{A(A&);//m;returnm.begin()==m.end();//line9}-std=c++11的错误是,gccversion4.9.020140302(experimental)(GCC):ali@X230:~/tmp$~/gcc/install/bin/g++-std=c++11cctor.cppInfileincludedfrom/home/ali/gcc/install/include/c++/4.9.0/bits/stl_algob

c++ - 比较两个map::iterators:为什么需要std::pair的拷贝构造函数?

下面非常简单的代码在C++98中编译和链接时不会出现警告,但在C++11模式下会出现难以理解的编译错误。#includestructA{A(A&);//m;returnm.begin()==m.end();//line9}-std=c++11的错误是,gccversion4.9.020140302(experimental)(GCC):ali@X230:~/tmp$~/gcc/install/bin/g++-std=c++11cctor.cppInfileincludedfrom/home/ali/gcc/install/include/c++/4.9.0/bits/stl_algob

c++ - 如何避免 'implicit' 在 std::pair 中调用单参数构造函数

最初的问题是如何使用std::map>以一种安全的方式,因为相同类型的键和值非常容易出错。所以我决定为这个值创建一个简单的包装器:structComponentName{std::wstringname;//Iwanttoprohibitanyimplicitstring-ComponentNameconversions!!!explicitComponentName(conststd::wstring&_name):name(_name){}booloperatorcomponent_names_map;但是下面的代码运行良好!component_names_mapcomponent

c++ - 如何避免 'implicit' 在 std::pair 中调用单参数构造函数

最初的问题是如何使用std::map>以一种安全的方式,因为相同类型的键和值非常容易出错。所以我决定为这个值创建一个简单的包装器:structComponentName{std::wstringname;//Iwanttoprohibitanyimplicitstring-ComponentNameconversions!!!explicitComponentName(conststd::wstring&_name):name(_name){}booloperatorcomponent_names_map;但是下面的代码运行良好!component_names_mapcomponent