基于此链接条件编译(Delphi) CPUARM条件,如果模拟器应为false,设备为true,问题是它对我不起作用.我在用Delphi XE6, iOS Simulator 7.1
这是我的代码
{$IFDEF CPUARM}
s := 'iOS device';
{$ELSE}
s := 'iOS Simulator';
{$ENDIF}
Run Code Online (Sandbox Code Playgroud)
ps iOS模拟器正在VMWare虚拟机中运行.
这是我希望能够解析的示例 JSON:
[
{
"a":{
"username":"aaa",
"email":"aaa@gmail.com"
}
},
{
"b":{
"username":"bbb",
"email":"bbb@gmail.com"
}
}
]
Run Code Online (Sandbox Code Playgroud)
我需要调用getData('b', 'email')must 输出bbb@gmail.com!
我真的很难理解如何使用该System.JSON单元,但我无法得到解决方案!我希望能够编写一个从上述 JSON 结构中提取特定数据的函数。到目前为止,这是我的代码。在类构造函数中,我有:
var
FIds: TJSONArray;
begin
FIds := TJSONObject.ParseJSONValue({json string here}) as TJSONArray;
end;
Run Code Online (Sandbox Code Playgroud)
然后,在必须返回数据的函数中,我写了这个:
// 'name' can be 'a' or 'b' | 'data' can be 'username' or 'email'
function TTest.getData(const name, data: string): string;
var
FValue, FValueInner: TJSONValue;
begin
for FValue in Fids do
begin
if (FValue is TJSONArray) then
begin
//Here I …Run Code Online (Sandbox Code Playgroud) 是否可以将函数(或其他符号)导入命名空间但不导出它?例如,我想导入std::string当前的命名空间,但我不想current::string显示.
namespace current {
using std::string;
string func();
}
Run Code Online (Sandbox Code Playgroud)
current::string 不应该是一件事.
用例只是减少打字(并且不断忘记std::string其他)并使代码更清晰,而不会使所有命名空间语法混乱代码.
我有一个功能对象,它是另一个功能的包装:
template <typename FuncT>
class Wrapper
{
private:
FuncT funcToWrap;
public:
Wrapper(FuncT ftw) : funcToWrap(ftw){};
template<typename ...ARG>
typename std::result_of<FuncT(ARG&&...)>::type operator()(ARG&&... args){
return funcToWrap(std::forward<ARG>(args)...);
}
};
int main(){
std::function<void()> testfunc = [](){ std::cout << "Test" << std::endl; };
Wrapper<decltype(testfunc)> test{testfunc};
test();
}
Run Code Online (Sandbox Code Playgroud)
我想这样做是为了纪念operator()为[[nodiscard]]如果std::result_of<FuncT(ARG&&...)>::type不是void。
我注意到的是,当我将[[nodiscard]]返回类型的模板评估的情况设为时void,它将被编译器忽略。
这是我可以依靠的行为吗?
我很难理解如何阻止代码std::conditional_t在错误分支中被评估。
#include <type_traits>\n\nusing namespace std;\n\nnamespace {\n template <typename T>\n using BaseDifferenceType = decltype (T{} - T{});\n}\n\nint main ()\n{\n using T = int;\n static_assert(! is_enum_v<T>);\n BaseDifferenceType<T> xxx {};\n \n // PROBLEM IS HERE - though is_enum is false, we still evaluate underlying_type<T> and complain it fails\n using aaa = conditional_t<is_enum_v<T>, underlying_type_t<T>, BaseDifferenceType<T>>;\n \n return 0;\n}\nRun Code Online (Sandbox Code Playgroud)\n您可以在https://www.onlinegdb.com/uxlpSWVXr在线尝试此操作。
\n编译(使用 C++17)给出错误:
\n#include <type_traits>\n\nusing namespace std;\n\nnamespace {\n template <typename T>\n using BaseDifferenceType = decltype (T{} - T{});\n}\n\nint …Run Code Online (Sandbox Code Playgroud) template<typename T=double>
constexpr T pi = T(3.14159265358979323846264338328);
template<>
constexpr const char* pi<const char*> = "?";
Run Code Online (Sandbox Code Playgroud)
使用 clang 编译器(Apple clang 版本 12.0.0)(使用 C++14),这会触发警告(使用-Weverything):
之前没有非静态变量 'pi<const char *>' 的 extern 声明
如果变量不打算在此翻译单元之外使用,则声明“静态”
此外,由于这是在标头中定义的,因此创建了多个 'myNameSpace::pi<char const*>' 实例,导致链接器错误。
因此,按照建议,我添加了static关键字,从而使警告静音:
template<>
static constexpr const char* pi<const char*> = "?";
Run Code Online (Sandbox Code Playgroud)
但是现在gcc(9.3.0)不爽,报错指向static关键字:
错误:显式模板特化不能有存储类
避免警告和错误的正确方法是什么?
您可以在 C++ 中定义可变参数宏,如下所示:
#define FOO(x, ...) bar(x, __VA_ARGS__)
Run Code Online (Sandbox Code Playgroud)
但是调用FOOasFOO(1)会导致宏扩展bar(1,),这显然是一个语法错误并且无法编译。
因此 GCC 包含一个 GNU 扩展:
#define FOO(x, ...) bar(x, ##__VA_ARGS__)
Run Code Online (Sandbox Code Playgroud)
这会将给定的示例扩展到所需的结果bar(1)。虽然__VA_ARGS__它是一个 GNU 扩展,但它也受到 clang 的支持,但它会在以下位置发出警告-pedantic flag:
警告:“,”和 __VA_ARGS__ 的标记粘贴是 GNU 扩展 [-Wgnu-zero-variadic-macro-arguments]。
因此,C++20 包含一种新机制,以符合标准的方式实现所需结果:
#define FOO(x, ...) bar(x __VA_OPT__(,) __VA_ARGS__)
Run Code Online (Sandbox Code Playgroud)
,仅当以下内容不为空时才会添加__VA_ARGS__,否则将省略,. 这个新扩展目前适用于 GCC 和 clang trunk(启用该-std=c++2a标志): https: //godbolt.org/z/k2nAE6。
我唯一的问题是 clang 在以下位置发出警告-pedantic:
警告:必须为可变参数宏的“...”参数指定至少一个参数 [-Wgnu-zero-variadic-macro-arguments](GCC 不会发出警告)。
但为什么?__VA_ARGS__只有当有人只使用宏并且不向宏传递任何参数时,这似乎才有意义。但通过新的扩展, …
在我的 mozilla 日志中,我收到以下错误:
根据声明的字符编码,字节流是错误的。字符编码声明可能不正确。
同时,在我的 doctype 元下声明了 UTF8 字符集:
<!DOCTYPE html><html lang="en"><head prefix="og: http://ogp.me/ns# article: http://ogp.me/ns/article# fb: http://ogp.me/ns/fb# website: http://ogp.me/ns/website#"><meta charset="utf-8"><meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0"><meta name="msvalidate.01" content="232BB6672CFDF39D90402F9473F59D51"><title>What are the Terms of the Covenant of Settlement ? :. Bishop David Oyedepo, Questions and Answers, + Pdf</title>
Run Code Online (Sandbox Code Playgroud)
我在用<meta charset="utf-8">。为什么我会收到此错误,如何解决?
https://en.cppreference.com/w/cpp/language/function-try-block的引用有错字吗?
到达析构函数上的函数 try 块的 catch 子句末尾也会自动重新抛出当前异常,就像 by 一样
throw;,但允许使用 return 语句。
似乎很难相信析构函数会自动重新抛出,因为我读过的每位专家的每一篇文章都说析构函数在任何情况下都不应该抛出。事实上,引用上方的示例代码显示了来自构造函数而不是析构函数的隐式抛出。
因此,我想知道,该语句是否错误,是否应该指示构造函数的行为?
当我开始思考这个问题时,我一直在阅读另一篇 StackOverflow 文章:C4297 warning in Visual Studio while using function-try-block (function Should not throw an exception but does)。它已经有了答案,但没有人质疑这句话一开始是否准确。
c++ ×6
delphi ×3
c++17 ×2
templates ×2
attributes ×1
c++14 ×1
clang ×1
delphi-xe6 ×1
json ×1
utf-8 ×1