包括什么意义
ios_base::sync_with_stdio(false);
cin.tie(NULL);
Run Code Online (Sandbox Code Playgroud)
在C++程序中?
在我的测试中,它加快了执行时间,但有一个测试用例,我应该担心包含这个吗?
这两个陈述总是必须在一起,或者第一个是否足够,即忽略cin.tie(NULL)?
此外,如果其值已设置为false?允许同时使用C和C++命令吗?
https://www.codechef.com/viewsolution/7316085
上面的代码运行正常,直到我scanf/printf在C++程序中使用值为true.在这种情况下,它给出了分段错误.可能的解释是什么?
请考虑以下代码:
struct bar
{
template <typename U>
void fun0() const {}
};
template <typename T>
struct foo
{
void
fun1(const bar& d)
{
// (1) KO
fun2(d).fun0<int>();
// (2) OK
fun2(d).template fun0<int>();
// (3) OK
d.fun0<int>();
}
bar
fun2(const bar& d)
{
return d;
}
};
Run Code Online (Sandbox Code Playgroud)
第(2)和(3)行编译,但(1)失败:
error: use 'template' keyword to treat 'fun0' as a dependent template name
fun2(d).fun0<int>();
^
template
Run Code Online (Sandbox Code Playgroud)
(正如所料,如果foo不再是模板结构,(1)也编译)
为什么bar::fun0依赖模板名称在这里?bar不依赖于模板参数T的foo.
编辑:
显然,bar::fun2负责处理的模糊性.template.例如,让我们添加以下2个免费函数: …
我有一个案例,我需要压缩很多通常很小的值.因此,我用可变长度字节编码压缩它们(ULEB128,具体):
size_t
compress_unsigned_int(unsigned int n, char* data)
{
size_t size = 0;
while (n > 127)
{
++size;
*data++ = (n & 127)|128;
n >>= 7;
}
*data++ = n;
return ++size;
}
Run Code Online (Sandbox Code Playgroud)
有没有更有效的方法(可能使用SSE)?
编辑:在此压缩之后,结果存储到data,取size字节.然后,在下一个unsigned int上调用压缩函数.
我正在研究一种从规范生成C代码的工具.因此,在将编译代码与其他工具一起使用之前,用户需要自己编译生成的代码.我想自动化这个繁琐的过程.我不知道是否可以使用libclang直接嵌入编译器,而不是调用一个进程?
我想在协程中打电话给coroutine.是否可以使用Boost.Coroutine?
我想'生成'函数指针的跳转表.指向的函数有两种类型的模板.应该为两个类型列表中的每个可能的对实例化一个不同的函数.理想情况下,我们可以有类似的东西:
#include <tuple>
template <typename X, typename Y>
void foo()
{}
template <typename... Xs, typename... Ys>
void bar(const std::tuple<Xs...>&, const std::tuple<Ys...>&)
{
using fun_ptr_type = void (*) (void);
static constexpr fun_ptr_type jump_table[sizeof...(Xs) * sizeof...(Ys)]
= {&foo<Xs, Ys>...};
}
int main ()
{
using tuple0 = std::tuple<int, char, double>;
using tuple1 = std::tuple<float, unsigned long>;
bar(tuple0{}, tuple1{});
}
Run Code Online (Sandbox Code Playgroud)
正如预期的那样,当元组具有不同的长度时它会失败:
foo.cc:15:20: error: pack expansion contains parameter packs 'Xs' and 'Ys' that have different lengths (3 vs. 2)
= {&foo<Xs, Ys>...};
~~ ~~ …Run Code Online (Sandbox Code Playgroud) 假设我们有以下类型
template <bool... Values>
struct foo{};
Run Code Online (Sandbox Code Playgroud)
我想从constexpr数组创建一个可变参数模板bool tab[N].换句话说,我想做的事情如下:
constexpr bool tab[3] = {true,false,true};
using ty1 = foo<tab[0], tab[1], tab[2]>;
Run Code Online (Sandbox Code Playgroud)
但我想以编程方式进行.现在,我尝试了以下内容:
template <std::size_t N, std::size_t... I>
auto
mk_foo_ty(const bool (&tab)[N], std::index_sequence<I...>)
{
// error: template argument for template type parameter must be a type
return foo<tab[I]...>{};
}
// error (see mk_foo_ty)
using ty2 = decltype(mk_ty(tab, std::make_index_sequence<3>{}));
// error: expected '(' for function-style cast or type construction
using ty3 = foo<(tab[std::make_index_sequence<3>])...>;
Run Code Online (Sandbox Code Playgroud)
我甚至不确定它是否可能.也许诉诸于像Boost.Preprocessor这样的东西,但我不喜欢这个想法.那么,有没有人有想法?谢谢!
编辑
我一边是constexpr布尔方形矩阵的框架,可以在编译时使用xor,否定等创建.
另一方面,我有一个模板框架,它使用布尔值作为参数,使用在可变参数模板中编码的信息静态创建操作.
我的目标是弥合这两个框架之间的差距.因此,我无法使用硬编码解决方案. …
我需要以任意精度获取值的哈希值(来自Boost.Multiprecision); 我用cpp_int后端.现在,我想出了以下代码:
boost::multiprecision::cpp_int x0 = 1;
const auto seed = std::hash<std::string>{}(x0.str());
Run Code Online (Sandbox Code Playgroud)
我不需要代码尽可能快,但我发现散列字符串表示非常笨拙.
所以我的问题是双重的:
double我可以轻松散列(我仍然会使用任意精度值进行哈希表所需的比较)?静态分析仪透析器(我通过dialyxir使用它)报告Logger(Logger.info "blah")的所有用法作为无与伦比的回报:
Expression produces a value of type 'ok' | {'error',_}, but this value is unmatched
Run Code Online (Sandbox Code Playgroud)
我可以写:ok = Logger.info "blah"但很明显,这很麻烦.我还可以配置透析器-Wno_unmatched_returns以忽略所有这些警告.但是,我发现它们非常有用,并且不想忽略它们.
透析器的文档说我们可以使用模块属性来基于每个模块停用警告,但是我无法看到是否只能将此信息放在Elixir源文件中.
有没有办法配置Dialyzer忽略这样的警告,但仅限于Logger?