在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++宏,以便代码可以识别标准?
例如,目前大多数编译器将"数组"放入"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
这段代码:
#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上失败.在PRId64
GCC 4.7.1编译之前添加空格.
哪一个是正确的?
什么时候会给出不同的答案,这种差异什么时候会有用呢?
有没有任何具体的情况下,你不能正确地做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表达式的版本更简短,通常更易读(尽管对此可能有不同的看法)。因此,我不明白为什么将它与折叠表达式一起添加到库中。
当模板公开继承自另一个模板时,不是应该可访问的基本公共方法吗?
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++ 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
Qt创建者可以完美地构建和运行我的项目,但它会直接跳过我设置的任何断点.我找不到任何方法来解决这个问题,我会感激一些帮助.
编辑:SDK以调试模式构建,项目构建配置设置为调试.
我的内部健全性检查失败,所以我在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
,则失败.我不知道为什么.我怎样才能做到这一点?我有一个函数,它返回一个对或元组,具体取决于传递给它的参数,并希望验证它在正确的情况下实际返回一对或元组.
所有基本比较(<
, <=
, ==
, !=
, >=
, >
)都有一个关联的函数对象(std::less
, std::less_equal
, std::equal_to
, std::not_equal_to
, std::greater_equal
, std::greater
)。
飞船操作员<=>
有类似的函数对象吗?如果没有,为什么没有将其添加到标准库中?
c++ ×9
c++11 ×6
templates ×2
bimap ×1
breakpoints ×1
c++17 ×1
c++20 ×1
c99 ×1
inheritance ×1
map ×1
printf ×1
qt ×1
qt-creator ×1
std-pair ×1
stl ×1
type-traits ×1