小编Vin*_*ent的帖子

Clang和Intel无法编译此CRTP代码

我编写了一个小型库,它使用了大量的C++ 11元编程技术和CRTP,它与g ++ 4.7.2编译得很好.

现在,我尝试使用Intel icpc 13.0.0.079进行编译,它会产生数百个错误.所以我试着一个接一个地隔离问题.

所以,首先,考虑一下在g ++ 4.7.2下编译没有问题的代码

#include <iostream>

template<template<typename> class Crtp, typename Type>
struct Base {};

template<typename Type>
struct Derived : public Base<Derived, Type>
{
    Derived(): Base<Derived, Type>() {;}
};

int main()
{
    Derived<int> x;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

icpc和clang都无法编译此代码:

test_crtp.cpp(26): error: type "Derived<Type>::Derived" is not a class template
      Derived(): Base<Derived, Type>() {;}
                      ^

test_crtp.cpp(26): error: "Base" is not a nonstatic data member or base class of class "Derived<int>"
      Derived(): Base<Derived, Type>() {;}
                 ^
          detected during instantiation …
Run Code Online (Sandbox Code Playgroud)

c++ templates compiler-errors crtp c++11

11
推荐指数
2
解决办法
505
查看次数

检查矩阵是否是单数的快速方法?(不可逆,det = 0)

什么是最快的算法(链接到C或C++的例子很酷)来检查小方矩阵(<16*16元素)是否是单数(不可逆,det = 0)?

algorithm matrix matrix-inverse

10
推荐指数
1
解决办法
2万
查看次数

g ++ 4.7.1编译错误:'strsignal'的冲突类型

我正在尝试在Ubuntu 12.04 32位上从源代码编译g ++ 4.7.1.目前我完全做到了这一点:https://askubuntu.com/questions/168947/how-to-upgrade-g-to-4-7-1 除了在编译g ++ 4.7.1之前,它问我"取消设置LIBRARY_PATH"(所以我已经这样做了).所以编译开始了,过了一会儿我有以下错误信息:

In file included from ../.././gcc/c-lang.c:24:0:
../.././gcc/system.h:499:20: erreur: conflicting types for ‘strsignal’
/usr/include/string.h:566:14: note: previous declaration of ‘strsignal’ was here
In file included from ./tm.h:19:0,
                 from ../.././gcc/c-lang.c:26:
./options.h:3738:2: erreur: #error too many masks for ix86_isa_flags
In file included from ../.././gcc/input.h:25:0,
                 from ../.././gcc/tree.h:27,
                 from ../.././gcc/c-lang.c:27:
../.././gcc/../libcpp/include/line-map.h:208:38: erreur: ‘CHAR_BIT’ undeclared here (not in a function)
../.././gcc/../libcpp/include/line-map.h:208:3: erreur: bit-field ‘reason’ width not an integer constant
../.././gcc/../libcpp/include/line-map.h:208:3: attention : ‘reason’ is narrower than values …
Run Code Online (Sandbox Code Playgroud)

c++ compilation g++ ubuntu-12.04

10
推荐指数
2
解决办法
5326
查看次数

constexpr类的设计:合并constexpr和非constexpr版本?

考虑一个只在运行时包装值的类:

template <typename Type>
class NonConstValue 
{
    public:
        NonConstValue(const Type& val) : _value(val) {;}
        Type get() const {return _value;}
        void set(const Type& val) const {_value = val;}
    protected:
        Type _value;
};
Run Code Online (Sandbox Code Playgroud)

和constexpr版本:

template <typename Type>
class ConstValue 
{
    public:
        constexpr ConstValue(const Type& val) : _value(val) {;}
        constexpr Type get() const {return _value;}
    protected:
        const Type _value;
};
Run Code Online (Sandbox Code Playgroud)

问题1:您能否确认constexpr版本是否以正确的方式设计?

问题2:如何将两个类混合成一个名为Value可以constexpr构造或运行时构造的类,其值可以get()在运行时或编译时?

编辑:问题3:如果get().cpp文件中定义,如果我想get()内联,如果它不是一个constexpr正确的函数声明?是吗

constexpr inline Type get();
Run Code Online (Sandbox Code Playgroud)

要么

inline …
Run Code Online (Sandbox Code Playgroud)

c++ constructor const constexpr c++11

10
推荐指数
1
解决办法
7620
查看次数

C++ 1z的范围状态?

C++委员会有一个范围研究小组:

http://isocpp.org/files/img/wg21-structure.png

但我没有按照这个研究组的历史记录,我不确定C++ 1z的预期交付类型(此外我不使用boost.range,所以我没有清楚地了解现有的做法).我们会有:

  1. 范围作为一对第一个/最后一个迭代器?

  2. 关于范围的联合和其他集合运算(例如[v.begin()+5, v.begin()+7[ U [v.begin()+10, v.begin()+15[ U [v.begin()+21, v.begin()+42[),即:union,intersection,disjoint union,complement?

  3. 迭代器过滤器(为了执行满足条件的for_each)?

  4. 其他事情?

c++ standards range c++11 c++17

10
推荐指数
1
解决办法
1660
查看次数

什么样的问题不转发普遍参考?

据我所知,在C++ 11中,应始终使用通用引用std::forward,但我不确定如果std::forward不使用会出现什么样的问题.

template <T>
void f(T&& x);
{
    // What if x is used without std::forward<T>(x) ?
}
Run Code Online (Sandbox Code Playgroud)

你能否举例说明在这种情况下可能出现的问题?

c++ perfect-forwarding c++11 universal-reference

10
推荐指数
3
解决办法
364
查看次数

Callable概念和std :: is_function类型特征之间有什么区别?

C++ 17将有一个Callable概念,我想知道与其类型的确切区别std::is_function<T>::value是什么true.它们是等价的吗?是另一个的超集吗?

c++ function-pointers function

10
推荐指数
1
解决办法
401
查看次数

std :: addressof作为C++中的常量表达式17

std::addressofC++ 17 的规范已经改变:现在允许它是一个常量表达式.但是,cppreference说:

表达式std::addressof(E)是一个常量子表达式,如果E是左值常量子表达式.

  • 什么是常量子表达式?
  • 什么是std::addressof(E)恒定表达式的例子?
  • 什么是std::addressof(E)不是常量表达式的例子?

c++ memory addressof constexpr c++17

10
推荐指数
1
解决办法
337
查看次数

在ac数组上获取begin的返回类型

我想以std::begin通用的方式获得返回类型.我目前的解决方案是:

using type = decltype(std::begin(std::declval<T>()));
Run Code Online (Sandbox Code Playgroud)

它适用于T = std::vector<int>.但我不明白为什么以下不起作用:

using type = decltype(std::begin(std::declval<int[3]>()));
Run Code Online (Sandbox Code Playgroud)

我收到错误:

example.cpp:83:60: error: no matching function for call to ‘begin(int [3])’
     using type = decltype(std::begin(std::declval<int[3]>()));
Run Code Online (Sandbox Code Playgroud)

如何以std::begin通用方式获取返回类型?

c++ templates iterator decltype c++11

10
推荐指数
1
解决办法
245
查看次数

是否可以实例化具有已删除的构造函数和析构函数的非聚合类?

考虑以下课程:

template <class T>
class object {
public:
    using type = T;

    object() = delete;
    object(const object&) = delete;
    object(object&&) = delete;
    object& operator=(const object&) = delete;
    object& operator=(object&&) = delete;
    ~object() = delete;

private:
    type value = 0;
};
Run Code Online (Sandbox Code Playgroud)

是否有可能object<int>通过任何奇怪的诡计来实例化一个对象(在堆栈上(可能不是)或在堆上(可能是?)),或者它是否不可能以object<int>任何可想象的形式存在(形式良好且定义明确)行为)C++17计划?

附录:首先我们考虑非格式的NDR程序/非未定义的行为.当且仅当可能存在形式错误的NDR程序/未定义的行为程序时,您可以用这样的程序说明答案.

c++ casting object instantiation c++17

10
推荐指数
1
解决办法
200
查看次数