小编rub*_*nvb的帖子

在c ++ 11中是否有Boost.Bimap替代方案?

在C++ 0x中有没有可用的替代Boost的bimap?

我想避免使用Boost,但完全接受C++ 11.如果有必要的话,在我的程序中,Boost的bimap的精简版本对我有用(我需要一个恒定的bimap来在枚举和相应的字符串之间切换).地图将是编译时常量,因此即使两个手动维护的地图也不是最佳解决方案.

谢谢!

更新:我在代码项目中找到了这个,但似乎许可可能是一个问题:http://www.codeproject.com/KB/stl/bimap.aspx? fid = 12042&df = 90&mpp = 25&noise = 3&sort = Position&view = Quick&fr = 151#xx0xx

我只是在寻找一个干净简单的解决方案(一个标题/源文件或一点额外,因为在我的情况下两个镜像地图同样好).

c++ stl map bimap c++11

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

C++ 11预定义的宏

是否有任何预定义的C++宏,以便代码可以识别标准?

例如,目前大多数编译器将"数组"放入"tr1"文件夹,但对于C++ 11,它将成为STL的一部分.所以目前

#include <tr1/array>
Run Code Online (Sandbox Code Playgroud)

但是c ++ 11

#include <array>
Run Code Online (Sandbox Code Playgroud)

什么是03标准和11标准的预定义宏,我可以使用它#ifdef来识别?

另外,我想C90和C99有宏吗?

Thanksx

c++ c++11

23
推荐指数
3
解决办法
1万
查看次数

C99 printf格式化程序与C++ 11用户定义文字

这段代码:

#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
int main(int argc,char **argv)
{
   uint64_t val=1234567890;
   printf("%"PRId64"\n",val);
   exit(0);
}
Run Code Online (Sandbox Code Playgroud)

根据GCC 4.5,适用于C99,C++ 03,C++ 11,但根据GCC 4.7.1,在C++ 11上失败.在PRId64GCC 4.7.1编译之前添加空格.

哪一个是正确的?

c++ printf c99 code-translation c++11

23
推荐指数
1
解决办法
7386
查看次数

is_trivially_copyable和is_trivially_copy_constructible有什么区别?

什么时候会给出不同的答案,这种差异什么时候会有用呢?

c++ type-traits c++11

23
推荐指数
1
解决办法
3025
查看次数

是否有理由使用std :: conjunction / std :: disjunction而不是在&amp;&amp; // |||上的折叠表达式?

有没有任何具体的情况下,你不能正确地做std::conjunction/ std::disjunction和不使用更多的“根本”(即语言特性,而不是库功能)在折叠式&&/ ||

例:

// func is enabled if all Ts... have the same type
template<typename T, typename... Ts>
std::enable_if_t<std::conjunction_v<std::is_same<T, Ts>...> >
func(T, Ts...) {
 // TODO something to show
}
Run Code Online (Sandbox Code Playgroud)

// func is enabled if all Ts... have the same type
template<typename T, typename... Ts>
std::enable_if_t<(std::is_same<T, Ts> &&...)>
func(T, Ts...) {
 // TODO something to show
}
Run Code Online (Sandbox Code Playgroud)

使用fold表达式的版本更简短,通常更易读(尽管对此可能有不同的看法)。因此,我不明白为什么将它与折叠表达式一起添加到库中。

c++ variadic-templates fold-expression c++17

23
推荐指数
1
解决办法
800
查看次数

C++中的继承和模板 - 为什么继承成员不可见?

当模板公开继承自另一个模板时,不是应该可访问的基本公共方法吗?

template <int a>
class Test {
public:
    Test() {}
    int MyMethod1() { return a; }
};

template <int b>
class Another : public Test<b>
{
public:
    Another() {}
    void MyMethod2() {
        MyMethod1();
    }
};

int main()
{
    Another<5> a;
    a.MyMethod1();
    a.MyMethod2();
}
Run Code Online (Sandbox Code Playgroud)

好吧,海湾合作委员会对此嗤之以鼻......我必须遗漏一些完全明显的东西(大脑融化).救命?

c++ inheritance templates

22
推荐指数
3
解决办法
2万
查看次数

为什么std :: make_tuple(7 + N ...)在C++ 11中合法?

以下代码在C++ 11中是合法的.

template<int... N>
std::tuple<decltype(N)...> f()
{
    return std::make_tuple(7 + N...); 
}
Run Code Online (Sandbox Code Playgroud)

这是什么意思?

c++ templates compile-time-constant variadic-templates c++11

21
推荐指数
1
解决办法
726
查看次数

为什么我的断点不能在Qt Creator中运行

Qt创建者可以完美地构建和运行我的项目,但它会直接跳过我设置的任何断点.我找不到任何方法来解决这个问题,我会感激一些帮助.

编辑:SDK以调试模式构建,项目构建配置设置为调试.

qt breakpoints qt-creator

20
推荐指数
4
解决办法
2万
查看次数

为什么std :: make_pair不返回一对?或者是吗?

我的内部健全性检查失败,所以我在Stackoverflow上重新运行它.

以下代码:

#include <iostream>
#include <typeinfo>
#include <utility>

int main()
{
    constexpr auto pair_of_ints = std::make_pair(1, 2);
    std::cerr << typeid(pair_of_ints).name();
    //static_assert(std::is_same<decltype(pair_of_ints), std::pair<int, int>>::value, "WTF");
}
Run Code Online (Sandbox Code Playgroud)

std::__1::pair<int, int>在我的系统上生成受损的符号名称(XCode Clang 8.x).

如果我然后启用它static_assert,则失败.我不知道为什么.我怎样才能做到这一点?我有一个函数,它返回一个对或元组,具体取决于传递给它的参数,并希望验证它在正确的情况下实际返回一对或元组.

c++ static-assert c++11 std-pair

20
推荐指数
1
解决办法
2554
查看次数

宇宙飞船操作员是否有 std::less/std::greater ?

所有基本比较(<, <=, ==, !=, >=, >)都有一个关联的函数对象(std::less, std::less_equal, std::equal_to, std::not_equal_to, std::greater_equal, std::greater)。

飞船操作员<=>有类似的函数对象吗?如果没有,为什么没有将其添加到标准库中?

c++ comparison-operators spaceship-operator c++20

20
推荐指数
1
解决办法
1006
查看次数