string_view
是C++ Library Fundamentals TS(N3921)中添加到C++ 17中的一个提议特性
据我所知,它是一种代表某种字符串"概念"的类型,它是任何类型的容器的视图,可以存储可视为字符串的东西.
const std::string&
参数类型应该
变成string_view
吗?string_view
需要考虑吗?在类中声明一个类是有效的.(嵌套类)
在类中声明命名空间无效.
问题是:是否有任何好的理由(除了c ++语法/语法问题)禁止在类中声明命名空间?
至于我为什么要这样做,这里有一个例子:
让我们对二叉树容器进行基本的转换
template<typename Data>
class binary_tree
{
public:
... stuff ....
private:
... iterators class declaration ...
public:
typedef left_depth_iterator_impl left_depth_iterator;
typedef right_depth_iterator_impl right_depth_iterator;
typedef left_breadth_iterator_impl left_breadth_iterator;
typedef right_breadth_iterator_impl right_breadth_iterator;
... stuff ....
private:
Data data;
binary_tree* left;
binary_tree* right;
};
Run Code Online (Sandbox Code Playgroud)
现在我注意到我的类中有很多迭代器,所以我想在同一个命名空间中重新组合它们,如下所示:
template<typename Data>
class binary_tree
{
public:
... stuff ....
private:
... iterators class declaration ...
public:
namespace iterator
{
typedef left_depth_iterator_impl left_depth;
typedef right_depth_iterator_impl right_depth;
typedef left_breadth_iterator_impl left_breadth;
typedef right_breadth_iterator_impl right_breadth;
}
... stuff …
Run Code Online (Sandbox Code Playgroud) 从C++ 14开始,我们可以使用泛型lambdas:
auto generic_lambda = [] (auto param) {};
Run Code Online (Sandbox Code Playgroud)
这基本上意味着它的调用操作符基于标记为auto的参数进行模板化.
问题是如何创建一个可以接受可变参数数量的lambda,类似于可变参数函数模板的工作方式?如果这不可能,最接近的东西可以用同样的方法吗?你会怎么存储它?有可能std::function
吗?
似乎联合可以在c ++ 11中进行模板化,例如在std :: optional的参考实现中使用它们.
那可能在c ++ 11之前吗?
我有两个GitHub存储库.
我想自动(可能使用钩子和/或github API)提交并将文件推送到第二个存储库,当它们被推送到第一个存储库时.
第二个存储库不是第一个存储库的克隆,它们的文件夹布局不一定相同,只有一堆共同的文件.
这样做最简单的方法是什么?
如果我不需要安装http服务器或学习perl,奖励积分:)
This is probably only a syntax problem.
So i have this template class :
template <typename String, template<class> class Allocator>
class basic_data_object
{
template<typename T>
using array_container = std::vector<T, Allocator<T>>;
};
Run Code Online (Sandbox Code Playgroud)
And another one :
template <typename String, template<class> class Allocator, typename T>
struct get_data_object_value
{
};
Run Code Online (Sandbox Code Playgroud)
Now i want to specialize the second one's T
parameter with the first one's inner typedef array_container
for any given type.
template <typename String, template<class> class Allocator, typename T>
struct get_data_object_value
<String, Allocator, …
Run Code Online (Sandbox Code Playgroud) 从c ++ 11开始,<string>
标头提供:
从转换为std::string
有符号整数。
我们也有他们的未签名副本:
现在,即使是一个孩子,也会注意到某些东西丢失了吗?:)
因此问题是:是否有理由不提供std::stoui
或仅仅是被遗忘的东西(基本上,这种“显而易见的”东西怎么会被遗忘)?
此外,是否意味着将一个正确的方式std::string
来unsigned int
为:
unsigned int ui = static_cast<unsigned int>(std::stoul(std::string{"42"}));
Run Code Online (Sandbox Code Playgroud) 所以我memory_pools
基于boost池创建了这个容器分配器类:
memory_pools.hpp
#ifndef MEMORY_POOL_HPP
# define MEMORY_POOLS_HPP
// boost
# include <boost/pool/pool.hpp>
# include <boost/unordered_map.hpp>
template<typename ElementType>
class memory_pools
{
public:
template <typename>
friend class memory_pools;
private:
using pool = boost::pool<>;
public:
using value_type = ElementType;
using pointer = value_type*;
using const_pointer = const value_type*;
using reference = value_type&;
using const_reference = const value_type&;
using size_type = pool::size_type;
using difference_type = pool::difference_type;
public:
template<typename OtherElementType>
struct rebind
{
using other = memory_pools<OtherElementType>;
};
public:
memory_pools();
template<typename SourceElement>
memory_pools(const …
Run Code Online (Sandbox Code Playgroud) 努力学习lvalues
,rvalues
并为他们分配内存.因此,有很多学习材料会有一些混乱.
An rvalue
是一个值,只需要在创建它的表达式的边界中存在(至少在C++ 11之前).所以它有一个占据的地址和内存块.但根据定义,我们无法得到一个地址rvalue
,因为它与一个临时对象形成鲜明对比lvalue
.但即使在C++ 11之前,我们也可以rvalue
通过从函数返回它并将其保存为const引用类型来获取地址(呃,我猜不是地址而是值).
那么,更确切地说,rvalue
分配如何运作?程序或操作系统在多长时间内真正记住了rvalue
创建并标记为已分配的内存位置,而另一个对象无法取代它?
我如何看待,现在rvalues
存储就像lvalues
我们只是有其他权限来访问它们.并且它们具有其他类型的释放 - 用于lvalues
超出范围,rvalues
可以通过存在于表达式边界中或者直到没有更多链接来优化.
在随机文档检查期间,cppreference.com
我注意到一些容器的新成员函数重载作为参数,恰好是一个新的标准类型,C++17
称为a Node Handle
.
现在,同一站点上的节点句柄的文档页面提供了有关如何工作的多个细节和技术行为,但它并没有真正正确地传达这种新类型的一般概念和目的.
因此,问题是什么是节点句柄?
c++ ×9
c++11 ×3
c++17 ×2
templates ×2
boost-pool ×1
c++14 ×1
class ×1
git ×1
githooks ×1
github ×1
github-api ×1
lambda ×1
memory ×1
namespaces ×1
performance ×1
rvalue ×1
stl ×1
string-view ×1
unions ×1
variadic ×1