我看看Generic lambdas并且无法得到它 - 为什么要保留类型声明?为什么不
(x, y)呢?如果编译器供应商必须支持(auto a, auto b)是否有任何支持简单的问题(a, b)?
据我了解,在C++ 11 char16_t和char32_t不是类型定义,但新的基本数据类型.(如果我错了,请纠正我).
我正在编写一个用于linux gcc和Windows Visual Studio的库.所以我写了一个特点:
template <class T>
struct IsChar : std::false_type {
};
template <>
struct IsChar<char> : std::true_type {
};
template <>
struct IsChar<wchar_t> : std::true_type {
};
template <>
struct IsChar<char16_t> : std::true_type {
};
template <>
struct IsChar<char32_t> : std::true_type {
};
Run Code Online (Sandbox Code Playgroud)
然而,我注意到,在VS(2013),char16_t和char32_t仅仅类型定义为unsigned short和unsigned在[..]\Microsoft Visual Studio 12.0\VC\include\yvals.h.
所以我查了一下
std::is_same<char32_t, unsigned>::value
是true在VS和false海湾合作委员会.
所以我的问题是:
char16_t和char32_t标准中的新原始类型(这两种类型的VS实现是非标准的吗?) …我将 Lua 表用作集合,将集合的值放入表键中并1作为表值,例如
function addToSet(s,...) for _,e in ipairs{...} do s[e]=1 end end
function removeFromSet(s,...) for _,e in ipairs{...} do s[e]=nil end end
local logics = {}
addToSet(logics,true,false,"maybe")
Run Code Online (Sandbox Code Playgroud)
为了测试两组是否相等,我需要确保它们具有完全相同的键。什么是有效的方法来做到这一点?
继承期间类的默认可见性模式是什么(此处为D @ class中的B)
class B {
public:
int key;
B(void) { key = 0; printf("B constructed\n");}
virtual void Tell(void);
~B(void) {cout <<"B destroyed"<<endl << endl;}
};
class D2 : B {
public:
void Tell(void) { printf("D2 Here\n"); }
};
Run Code Online (Sandbox Code Playgroud) 是否可以手动将纪元日期/时间设置为0000年1月1日,因此我可以使用std :: chrono :: time_point :: time_since_epoch来计算给定日期与1月1日0000之间的差异?
我尝试了以下方法:
#include <iostream>
#include <chrono>
#include <ctime>
int main(int argc, char*argv[])
{
std::tm epochStart = {};
epochStart.tm_sec = 0;
epochStart.tm_min = 0;
epochStart.tm_hour = 0;
epochStart.tm_mday = 0;
epochStart.tm_mon = 0;
epochStart.tm_year = -1900;
epochStart.tm_wday = 0;
epochStart.tm_yday = 0;
epochStart.tm_isdst = -1;
std::time_t base = std::mktime(&epochStart);
std::chrono::system_clock::time_point baseTp=
std::chrono::system_clock::from_time_t(base);
std::time_t btp = std::chrono::system_clock::to_time_t(baseTp);
std::cout << "time: " << std::ctime(&btp);
}
Run Code Online (Sandbox Code Playgroud)
但这给了我
time: Thu Jan 1 00:59:59 1970
Run Code Online (Sandbox Code Playgroud) 我有一个需要将任务安排到libuv事件循环的函数.我的想法是创建一个0ms超时的计时器.我试过以下代码:
void myFunction() {
...
uv_timer_t* timer = new uv_timer_t();
uv_timer_init(uv_default_loop(), timer);
uv_timer_start(timer, [&](uv_timer_t* timer, int status) {
// Scheduled task
}, 0, 0);
}
Run Code Online (Sandbox Code Playgroud)
这种方法运行良好但问题是,动态分配的计时器永远不会被释放.我已经尝试在回调中释放计时器,但这导致了分段错误:
void myFunction() {
...
uv_timer_t* timer = new uv_timer_t();
uv_timer_init(uv_default_loop(), timer);
uv_timer_start(timer, [&](uv_timer_t* timer, int status) {
// Scheduled task
delete timer;
}, 0, 0);
}
Run Code Online (Sandbox Code Playgroud)
我也尝试过调用uv_timer_stop(timer);并uv_unref((uv_handle_t*) timer);在实际内存释放之前,但是分段错误仍然是remian.
我正在尝试Eigen为容器类完成类似于高级初始化的操作.
即在main,我想填写类型的对象DynamicArray如下:
main.cpp中
// Create 3 x 3 Dynamic array and fill with 0's
DynamicArray da(3, 3, 0);
da << 1, 2, 3,
4, 5, 6,
7, 8, 9;
Run Code Online (Sandbox Code Playgroud)
我用来尝试实现此目的的方法是:
DynamicArray.hpp
template <typename T>
class DynamicArray {
// ...
public:
// ...
template <typename... Args,
typename = typename std::enable_if<ArgPackSameTruth<
std::is_convertible<Args, T>...>::value,
T>::type
> void operator<<(Args... x) {
typename std::vector<T> arg_vect{std::forward<Args>(x)...};
std::cout << arg_vect.size() << "\n";
// Load contents of arg_vect into *this...
return;
} …Run Code Online (Sandbox Code Playgroud) 我的二进制搜索树析构函数看起来像这样.
~BSTree()
{
if (this == nullptr || this->left == nullptr && this->right == nullptr)
{
return;
}
this->left->~BSTree();
delete this->left;
this->right->~BSTree();
delete this->right;
}
Run Code Online (Sandbox Code Playgroud)
调用堆栈获取有关> = 4后叫我的程序崩溃在if()与访问Voilation例外.
我的领域是只有三个:int key;,BSTree *left;和BSTree *right;

它似乎this不是NULL但它的字段无法从内存中读取.如何检查是否可以,remove this;如果不能防止异常?
c++ ×7
c++11 ×5
c++-chrono ×1
c++14 ×1
epoch ×1
event-loop ×1
exception ×1
gcc ×1
inheritance ×1
lambda ×1
lua ×1
memory ×1
memory-leaks ×1
performance ×1
set ×1