小编And*_*zos的帖子

内联命名空间和 using 指令在 C++11 中的区别?

有什么区别:

namespace A
{
    inline namespace B
    {
        ...
    }

    ...
}

...
Run Code Online (Sandbox Code Playgroud)

namespace A
{
    namespace B
    {
        ...
    }

    using namespace B;

    ...
}

...
Run Code Online (Sandbox Code Playgroud)

也就是说,内联命名空间和在其封闭命名空间中放置了 using 指令的非内联命名空间有什么区别?

c++ c++11

5
推荐指数
1
解决办法
855
查看次数

C++ 11`nullptr_t`返回函数被省略了?

以下C++ 11程序在gcc 4.7.2下不输出任何内容:

#include <iostream>
using namespace std;

decltype(nullptr) g()
{
    cout << "foo" << endl;
    return nullptr;
}

int* f()
{
    return g();
}

int main(int argc, char** argv)
{
    auto x = f();
}
Run Code Online (Sandbox Code Playgroud)

这是正确的行为,还是编译器错误?

更新:

多谢你们.仅供参考我的解决方法:

 struct NullPointer
 {
     template<class T> operator T*()
     {
          volatile decltype(nullptr) np = nullptr;
          return np;
     }
     operator bool()
     {
          volatile bool b = false;
          return b;
     }
 };

 NullPointer g() { return {}; }
Run Code Online (Sandbox Code Playgroud)

c++ gcc c++11

5
推荐指数
1
解决办法
209
查看次数

C++ 11标准库中值和对象的示例?

在C++ 11 3p3中,它指出:

实体是,对象,引用,函数,枚举器,类型,类成员,模板,模板特化,命名空间,参数包或此.

在17.6.1.1p1中,它指出:

C++标准库提供以下类型实体的定义:宏,,类型,模板,类,函数,对象.

什么是C++标准库为(不是对象?)和对话提供定义的值的示例:C++标准库为其定义的对象的示例是什么,不是值?

c++ object language-lawyer c++11

5
推荐指数
1
解决办法
258
查看次数

C++ 1y/14:自动变量模板?

以下C++ 1y/C++ 14程序是否格式错误?

template<class> constexpr auto X = 42;

int main()
{
        static_assert(X<int> == 42, "");
}
Run Code Online (Sandbox Code Playgroud)

为什么/为什么不呢?

Clang trunk抱怨说:

error: invalid operands to binary expression ('auto' and 'int')
Run Code Online (Sandbox Code Playgroud)

c++ c++14

5
推荐指数
1
解决办法
256
查看次数

C++ 1y/C++ 14:将静态constexpr数组转换为非类型模板参数包?

假设我有一个静态存储持续时间的constexpr数组(已知绑定):

constexpr T input[] = /* ... */;
Run Code Online (Sandbox Code Playgroud)

我有一个需要包的输出类模板:

template<T...> struct output_template;
Run Code Online (Sandbox Code Playgroud)

我想实例化output_template如下:

using output = output_template<input[0], input[1], ..., input[n-1]>;
Run Code Online (Sandbox Code Playgroud)

一种方法是:

template<size_t n, const T (&a)[n]>
struct make_output_template
{
    template<size_t... i> static constexpr
    output_template<a[i]...> f(std::index_sequence<i...>)
    { return {}; };

    using type = decltype(f(std::make_index_sequence<n>()));
};

using output = make_output_template<std::extent_v<decltype(input)>, input>::type;
Run Code Online (Sandbox Code Playgroud)

我缺少更清洁或更简单的解决方案吗?

c++ templates variadic-templates constexpr c++14

5
推荐指数
1
解决办法
869
查看次数

std :: remove_cv应该在const T的数组上产生什么类型?

应该std::remove_cv<const int[3]>生产什么类型?int[3]还是const int[3]

const int[3]array of 3 const int对的?,没有顶级的cv-qualifier.所以它不应该产生const int[3]吗?int[3]我认为最新版本的gcc/libstdc ++正在制作中.这是一个错误吗?为什么/为什么不呢?

c++ libstdc++ type-traits c++14

5
推荐指数
1
解决办法
139
查看次数

odr使用转发的constexpr参数?

在下面的...

struct C {};
constexpr C c;

void g(C);

template<typename T>
void f(T&& t) {
  g(std::forward<T>(t));
}

int main() {
  f(c);
}
Run Code Online (Sandbox Code Playgroud)

是否使用了codr?为什么/为什么不呢?

c++ c++14

5
推荐指数
1
解决办法
124
查看次数

专门的内部类模板的功能的外层定义?

请考虑以下不正确的计划:

struct S {
    template<class T> struct J { };
};

template<>
struct S::J<void> {
    void f();
};

template<>
void S::J<void>::f() {} // ERROR

$ clang++ -std=c++11 test.cpp 
no function template matches function template specialization 'f'

$ g++ -std=c++11 test.cpp
template-id ‘f<>’ for ‘void S::J<void>::f()’ does not match any template declaration
Run Code Online (Sandbox Code Playgroud)

为什么没有f编译的定义?如何f在上面正确定义功能?

c++ templates template-specialization c++11 c++14

5
推荐指数
1
解决办法
248
查看次数

在套接字API方面主动关闭与被动关闭?

在TCP中,我们说连接的一侧执行"主动关闭"而另一侧执行"被动关闭".

就Linux套接字API而言,您如何区分主动关闭和被动关闭?

例如,假设我们有两个连接的Linux TCP套接字A和P,它们通过应用程序级协议交换信息,并且它们都知道是时候关闭它们的套接字(既不希望发送或接收更多数据到或彼此).

我们希望套接字A执行主动关闭,而P则是被动关闭.

A和P可以做一些事情.例如:

  • 呼叫关闭(SHUT_WR)
  • 打电话给recv,期待0回来
  • 打电话给.
  • 别的

这些东西的组合以及A应按什么顺序进行?......以及这些东西的组合以及P应按什么顺序进行?

c sockets linux tcp

5
推荐指数
1
解决办法
3180
查看次数

[temp.spec]/6的起源故事?

[temp.spec]/6读取:

通常的访问检查规则并不适用于名称在显式实例或明确专门的声明,与出现在函数体中,默认参数,基本条款,成员规格,枚举列表,或静态数据的名称除外成员或变量模板初始化程序.[注意:特别是,函数声明符中使用的模板参数和名称(包括参数类型,返回类型和异常规范)可能是通常无法访问的私有类型或对象. - 结束说明]

这条规则背后的动机是什么?哪个提案引入了它(或者它是古老的?),为什么?

c++ access-control template-specialization language-lawyer template-instantiation

5
推荐指数
1
解决办法
153
查看次数