这是从我在将小型异常处理库集成到由单个 Visual Studio 解决方案中的约 200 个 Visual C++ 项目组成的代码库时遇到的一个看似小问题开始的。
我遇到了一个链接器问题,由这样的消息表示
3>B_Utils.lib(B_Utils.dll) : error LNK2005: "public: __cdecl ExceptionBase<class std::runtime_error>::ExceptionBase<class std::runtime_error>(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0?$ExceptionBase@Vruntime_error@std@@@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) already defined in TranslationUnit_2.obj
3>B_Utils.lib(B_Utils.dll) : error LNK2005: "public: virtual __cdecl ExceptionBase<class std::runtime_error>::~ExceptionBase<class std::runtime_error>(void)" (??1?$ExceptionBase@Vruntime_error@std@@@@UEAA@XZ) already defined in TranslationUnit_2.obj
3>B_Utils.lib(B_Utils.dll) : error LNK2005: "public: __cdecl ExceptionBase<class std::runtime_error>::ExceptionBase<class std::runtime_error>(class ExceptionBase<class std::runtime_error> const &)" (??0?$ExceptionBase@Vruntime_error@std@@@@QEAA@AEBV0@@Z) already defined in TranslationUnit_2.obj
Run Code Online (Sandbox Code Playgroud)
乍一看,它看起来是另一个典型的问题,可以通过典型的建议“尝试更改 #include 文件的顺序”或“将实现移出头文件”来解决,但事实并非如此。
我探索了许多类似的相关问题,例如this或this one,但没有一个适合我的情况。至少,建议的食谱对解决我的问题没有帮助。
此外,很早之前我们公司的人在迁移到VS2010的过程中遇到了另一个与Visual Studio链接器相关的问题,结果证明是链接器错误,请参见这里。无论如何,这都不符合我的情况。
所以这个小问题最终以整个小型研究告终。您可以在 github 上 …
我最近注意到,一旦我开始构建我正在使用的Visual Studio解决方案(~200个C++项目),我得到了大量的cl.exe进程.

我对并行运行的几个cl.exe的事实并不感到惊讶,因为我的项目设置了/MP选项.

但我希望它们的数量会受到Visual Studio"选项"中以下设置的限制.

我认为在4核PC上并行运行数十个进程并不是构建解决方案的最有效方法.
所以,基本上我有两个问题:
cl.exe实例数量?PS我通常使用Visual Studio 2013 Update 4编译我的解决方案,但Visual Studio 2017可以观察到相同的行为.
c++ visual-studio visual-c++ visual-studio-2013 visual-c++-2013
根据std::map 文档,它存储键值对std::pair<const Key, Value>,因此映射中的键是const.
现在假设我有一个std::map键是指向某些对象的指针.
struct S {};
struct Data {};
using MyMap = std::map<S*, Data>;
Run Code Online (Sandbox Code Playgroud)
我们还假设有一个foo接受S*参数的函数.
void foo(S* ptr) { /* modify the object (*ptr) */ }
Run Code Online (Sandbox Code Playgroud)
现在,问题是:当我MyMap使用基于范围的for循环迭代时,我能够将map元素键传递给foo:
MyMap m = getMyMapSomehow();
for (auto elem : m)
{
static_assert(std::is_const<decltype(elem.first)>::value, "Supposed to be `const S*`");
foo(elem.first); // why does it compile?
}
Run Code Online (Sandbox Code Playgroud)
所以,即使我的static_assert成功(所以我假设它的类型elem.first是const S*),foo编译的调用很好,因此看起来好像我能够修改指针到const后面的对象.
为什么我能做到这一点?
PS这是Coliru …
我是Scala的新手,所以希望你能在这个问题中容忍这个问题,如果你发现它是noobish :)
我写了一个函数,它使用yield语法返回一个Seq元素:
def calculateSomeMetrics(names: Seq[String]): Seq[Long] = {
for (name <- names) yield {
// some auxiliary actions
val metrics = somehowCalculateMetrics()
metrics
}
}
Run Code Online (Sandbox Code Playgroud)
现在我需要修改它以返回Map以保留原始名称对每个计算值:
def calculateSomeMetrics(names: Seq[String]): Map[String, Long] = { ... }
Run Code Online (Sandbox Code Playgroud)
我试图使用相同的yield语法,但产生一个元组而不是单个元素:
def calculateSomeMetrics(names: Seq[String]): Map[String, Long] = {
for (name <- names) yield {
// Everything is the same as before
(name, metrics)
}
}
Run Code Online (Sandbox Code Playgroud)
但是,编译器会Seq[(String, Long)]根据编译器错误消息对其进行解释
type mismatch;
found : Seq[(String, Long)]
required: Map[String, Long]
Run Code Online (Sandbox Code Playgroud)
所以我想知道,实现这样的事情的"规范Scala方式"是什么?
我有一个API端点,当使用GET调用该端点时,将在体内返回一个JSON对象数组,如下所示:
[
{"id": "321", "created": "2019-03-01", "updated": "2019-03-15"},
{"id": "123", "created": "2019-03-02", "updated": "2019-03-16"}
]
Run Code Online (Sandbox Code Playgroud)
我想用Spring MockMvc测试用例检查主体。该语句当前如下所示:
mockMvc.perform(get("/myapi/v1/goodstuff").
andExpect(status().isOk()).
andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)).
andExpect(jsonPath("$.*", isA(ArrayList.class))).
andExpect(jsonPath("$.*", hasSize(2))).
andExpect(jsonPath("$[0].id", is("321"))).
andExpect(jsonPath("$[0].created", is("2019-03-01"))).
andExpect(jsonPath("$[0].updated*", is("2019-03-15"))).
andExpect(jsonPath("$[1].id", is("1232"))).
andExpect(jsonPath("$[1].created", is("2019-03-02"))).
andExpect(jsonPath("$[1].updated*", is("2019-03-16")));
Run Code Online (Sandbox Code Playgroud)
但是,我的API的实现不能保证返回数组中JSON对象的顺序。如果这是一个字符串数组,我可以通过通过生成的匹配器来解决org.hamcrest.collection.IsIterableContainingInAnyOrder<T>.containsInAnyOrder。但是我在他们的文档中看不到适合我的情况的匹配器,也没有在Spring文档中的jsonPath方法描述中找到任何线索
通过快速搜索,我也没有找到与我在SO上的情况有关的任何东西,除了上面描述的字符串情况之外。当然,我可以将JSON对象转换为字符串。
但是我想知道,我是否可以为一个JSON对象列表解决此问题,将每个对象的每个字段一一比较(就像上面的代码片段所示),但是忽略了对象在集合中的顺序?
更新:Zgurskyi 提出了一个解决方案,可以帮助我简化原始示例。但是,在一个实际的实际示例中,还有2个输入:
is,例如:(更接近我的原始代码)
mockMvc.perform(get("/myapi/v1/greatstuff").
andExpect(status().isOk()).
andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)).
andExpect(jsonPath("$.*", isA(ArrayList.class))).
andExpect(jsonPath("$.*", hasSize(2))).
andExpect(jsonPath("$[0].id", is("321"))).
andExpect(jsonPath("$[0].did", anything())).
andExpect(jsonPath("$[0].createdTs", startsWith("2019-03-01"))).
andExpect(jsonPath("$[0].updatedTs", startsWith("2019-03-15"))).
andExpect(jsonPath("$[0].name", equalToIgnoringCase("wat"))).
andExpect(jsonPath("$[0].stringValues", containsInAnyOrder("a","b","c"))).
andExpect(jsonPath("$[1].id", is("1232"))). …Run Code Online (Sandbox Code Playgroud) 假设有 2 个 Spark DataFrame 我们想加入,无论出于何种原因:
val df1 = Seq(("A", 1), ("B", 2), ("C", 3)).toDF("agent", "in_count")
val df2 = Seq(("A", 2), ("C", 2), ("D", 2)).toDF("agent", "out_count")
Run Code Online (Sandbox Code Playgroud)
可以用这样的代码来完成:
val joinedDf = df1.as('d1).join(df2.as('d2), ($"d1.agent" === $"d2.agent"))
// Result:
val joinedDf.show
+-----+--------+-----+---------+
|agent|in_count|agent|out_count|
+-----+--------+-----+---------+
| A| 1| A| 2|
| C| 3| C| 2|
+-----+--------+-----+---------+
Run Code Online (Sandbox Code Playgroud)
现在,我不明白的是,为什么它只在我使用别名df1.as(d1)和时才起作用df2.as(d2)?我可以想象,如果我直截了当地写,列之间会出现名称冲突
val joinedDf = df1.join(df2, ($"df1.agent" === $"df2.agent")) // fails
Run Code Online (Sandbox Code Playgroud)
但是......我不明白为什么我不能.as(alias) 只使用两者中的一个 DF:
df1.as('d1).join(df2, ($"d1.agent" === $"df2.agent")).show()
Run Code Online (Sandbox Code Playgroud)
失败
org.apache.spark.sql.AnalysisException: cannot …Run Code Online (Sandbox Code Playgroud) c++ ×3
scala ×2
visual-c++ ×2
apache-spark ×1
const ×1
dictionary ×1
hamcrest ×1
java ×1
join ×1
linker ×1
mockmvc ×1
pointers ×1
seq ×1
spring ×1
spring-mvc ×1
stdmap ×1
stl ×1
yield ×1