有没有办法在编译时打印a constexpr或#defined值的值?我想要相当于std::cout <<或某种方式来做类似的事情
constexpr int PI_INT = 4;
static_assert(PI_INT == 3,
const_str_join("PI_INT must be 3, not ", const_int_to_str(PI_INT)));
Run Code Online (Sandbox Code Playgroud)
编辑:我可以用constexprs 做一些基本的编译时打印,至少在gcc上做类似的事情
template <int v>
struct display_non_zero_int_value;
template <>
struct display_non_zero_int_value<0> { static constexpr bool foo = true; };
static constexpr int v = 1;
static_assert(v == 0 && display_non_zero_int_value<v>::foo, "v == 0");
Run Code Online (Sandbox Code Playgroud)
这给了我error: incomplete type ‘display_non_zero_int_value<1>’ used in nested name specifier static_assert(v == 0 && display_non_zero_int_value<v>::foo, "v == 0");.(另一方面,icpc不太有帮助,只是说error: incomplete …
我想travis在没有红宝石宝石的机器上安装宝石,而我没有root.(我想加密与travis一起使用的东西.)我决定尝试安装rvm,因为https://rvm.io/rvm/install表明这是一种在没有root的情况下安装ruby的简单方法.但是,我马上就遇到了问题:
jgross@cagnode17:~$ \curl -L https://get.rvm.io | bash -s stable --ruby
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 13961 100 13961 0 0 15390 0 --:--:-- --:--:-- --:--:-- 170k
Please read and follow further instructions.
Press ENTER to continue.
Downloading RVM from wayneeseguin branch stable
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1083k …Run Code Online (Sandbox Code Playgroud) 有没有办法让git完全忽略符号链接(将它们保留在树中,但不能在结帐时创建它们)?或者,有没有办法在Linux上的符号链接和Windows上的快捷方式之间进行git转换?
上下文:我在Windows和Linux上使用git和一些LaTeX文件.在linux上,我有大量的样式文件存储在repo之外,并且从一堆地方符号链接.如果git将它们转换为Windows上的快捷方式(我有相同的周围目录/文件结构),或者如果git完全忽略它们,并且不检查它们(我的LaTeX发行版中有样式文件),它将正常工作视窗).
有没有一种很好的方法来分析Mathematica中的代码?我希望能够递归(即,如果我说f[a_] := b[a],然后Profile[f[1]]应该给出几乎相同的输出Profile[b[1]]),但我会满足于能够做一些像应用于Timing每个相关的子表达式.如果我没有像特殊情况这样的东西会很好Module,但我想,比如,Profile[Module[{x=1+2},x!]]给我一个类似的输出
Time Expression Result
0 1 1
0 2 2
0 1 + 2 3
0 x$1234 3
0 x$1234 ! 6
0 Module[{x=1+2},x!] 6
6
Run Code Online (Sandbox Code Playgroud) ListLinePlot做一些类似的东西,我可以得到彩色
ListLinePlot[Range[420, 680, 20], ColorFunction -> "VisibleSpectrum", ColorFunctionScaling -> False]
Run Code Online (Sandbox Code Playgroud)

但是,如帮助文件所示(" ColorFunction至少需要一个数据集Joined"),如果我做了相同的操作
ListPlot[Range[420, 680, 20], ColorFunction -> "VisibleSpectrum", ColorFunctionScaling -> False]
Run Code Online (Sandbox Code Playgroud)

我所有的观点都是蓝色的.有一个很好的方式来获得ColorFunction,为工作ListPlot与Joined -> False?
也就是说,是否有更好的方式来获得类似的东西
ListPlot[
List /@ Transpose[{Range[(680 - 420)/20 + 1], Range[420, 680, 20]}],
PlotMarkers -> ({Graphics[{#, Disk[]}], 0.05} & /@ ColorData["VisibleSpectrum"] /@ Range[420, 680, 20])
]
Run Code Online (Sandbox Code Playgroud)
?

(另外,有没有人解释为什么 Mathematica需要Joined -> True使用ColorFunction?)
编辑:我也在寻找一种ErrorListPlot在ErrorBarPlots包装中进行类似着色的方法.
我正在尝试编译依赖于gtkspell的东西,这取决于附魔,在MinGW下.我遇到的错误就像
gtkspell/gtkspell.c:757: undefined reference to '_imp__enchant_broker_init'
我怀疑这是因为我在尝试连接一个{静态,动态}库时,我应该链接到另一个,或者因为在imp之前只有一个下划线应该有两个; 我明白了
$ objdump -t /d/opt/enchant-1.6.0/lib/libenchant.a | grep enchant_broker_init
[ 85](sec 1)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x00002ac0 _enchant_broker_init
Run Code Online (Sandbox Code Playgroud)
和
$ objdump -t /d/opt/enchant-1.6.0/lib/libenchant.dll.a | grep enchant_broker_init
[ 6](sec 1)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 _enchant_broker_init
[ 7](sec 3)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 __imp__enchant_broker_init
Run Code Online (Sandbox Code Playgroud)
互联网(http://lists.freedesktop.org/archives/gstreamer-devel/2007-January/013975.html)表明,盗版来自于
_declspec(dll{import,export})
Run Code Online (Sandbox Code Playgroud)
虽然附魔似乎有用
__declspec(dll{import,export})
Run Code Online (Sandbox Code Playgroud)
并且注释掉enchant.h中的相关行会使gtkspell.c请求enchant_broker_init而不是_imp__enchant_broker_init,但不会更改libenchant中显示的符号.有没有办法让gcc不会破坏名称,或者是否有人对可能出现的问题/如何修复它有什么想法?
这是一个在我的系统上重现问题的最小例子:
如果我有一个包含内容的文件enchanttest1.c
#include <stdio.h>
#include <enchant.h>
int main()
{
#ifdef ENCHANT_MODULE_EXPORT
printf("\nEnchant found\n");
#else
printf("\nEnchant not found\n");
#endif …Run Code Online (Sandbox Code Playgroud) c ++ 11标准是否有关于模板化联合的说法?(我在http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf中找不到任何内容,但我没有仔细阅读.)
我有
template<typename T>
union u {
T a;
char b;
};
template<typename T>
u<T> make_u(T t) {
return { .a = t };
}
int main() {
return make_u<int>(1).a;
}
Run Code Online (Sandbox Code Playgroud)
此代码会导致icpc -std=c++11说error: a designator into a template-dependent type is not allowed,g++ -std=c++0x说error: expected primary-expression before ‘.’ token,和g++ -std=c++11(版本4.8.0(实验))的说法internal compiler error: in lookup_field_1, at cp/search.c:387.我可以通过更换得到解决这个{ .a = t }用t.但是,对于不是联盟第一个成员的字段,我不能这样做.有没有办法在模板化联合中选择除第一个成员之外的某个成员,其中相关成员是模板依赖的?(当然,我可以在堆栈上声明一个联合,并将该成员设置为我想要的值.但我无法在初始化列表或constexpr …
我想做点什么
foo[OptionsPattern[]] := OptionValue[b]
Options[foo] = {a -> 0, b :> OptionValue[a]};
foo[a -> 1]
Run Code Online (Sandbox Code Playgroud)
让Mathematica给我1,而不是0.有没有更好的方法来做到这一点
foo[OptionsPattern[]] := (
Options[foo] = {a -> 0, b :> OptionValue[a]};
OptionValue[b]
)
foo[a -> 1]
Run Code Online (Sandbox Code Playgroud)
?
首先,foo在每次调用时设置选项都是低效的,特别是如果foo有很多选项的话.
wolfram-mathematica options optional-parameters optional-values
我有一堆提交,比如A,B,C,D,我想保留B,C和D,然后提交(BCD)-1.如果我有许多我想要同时撤消的提交,那么最简单的方法是什么?
(我似乎记得看到一个关于这个的stackoverflow问题,这表明我hg update到A,然后调用hg commit一些参数,但我现在似乎无法找到这个问题.)
FOO=bar ./configure和autoconf生成的脚本./configure FOO=bar在哪里./configure有什么区别configure.am?我知道,前者设置环境变量FOO来bar运行该脚本之前./configure,后者将字符串FOO=bar来./configure.我认为./configure解释这个(并记住它?)设置变量FOO等于bar,但除此之外,我不知道.特别是,这样或那样做有什么好处吗?