英语不是我的母语;请原谅一些打字错误。谢谢。
我声明一个OLEDstream用构造函数命名的类,如下所示:
OLEDstream::OLEDstream( uint8_t num,
const uint8_t *pins,
void (*fAlarm)() = NULL,
int buffsz = 21*5,
const uint8_t *font = u8g2_font_6x10_mr,
int minx = 0,
int miny = 11,
int maxx = 120,
int maxy = 60,
int stepx = 6,
int stepy = 11 );
Run Code Online (Sandbox Code Playgroud)
在某些情况下,我想更改 的值stepy。然而,跳过中间的默认参数是不允许的(据我所知),所以我必须在调用它时传递所有参数,即使我只想更改stepy它的默认值。
函数重载似乎是一种解决方案,但有 8 个默认参数,很难预测用户想要更改哪一个。所以我必须将该函数重载 100 多次。
针对这种情况还有其他建议、建议或编程技巧吗?
我是编程新手,今天加入了 StackOverflow。我希望我可以根据指南询问:
我正在启动 SwiftUI,它似乎有许多代码仅适用于 iOS 17,请看一下:
if #available(iOS 17.0, *) {
Text("Hello World")
.font(.title.bold())
.multilineTextAlignment(.leading)
// This modifier only works on iOS 17
.foregroundStyle(.red)
} else {
Text("Hello World")
.font(.title.bold())
.multilineTextAlignment(.leading)
.foregroundColor(.red)
}
Run Code Online (Sandbox Code Playgroud)
我学到的第一件事就是不要重复相同的代码,但是如何在不重复代码的情况下轻松应用不同的修饰符?像这样的东西:
Text("Hello World")
.font(.title.bold())
.multilineTextAlignment(.leading)
if #available(iOS 17.0, *) {
.foregroundStyle(.red)
} else {
.foregroundColor(.red)
}
Run Code Online (Sandbox Code Playgroud)
PS:我见过这样的帖子来实现一个以 bool 作为输入的自定义修饰符,但它不能以编译器可以理解的方式获取操作系统版本,例如#available(iOS 17.0, *).
我知道我们可以实现类似的操作系统检查,如下所示,但我正在以相同的通用方式寻找版本检查:
Text("Hello World")
.font(.title.bold())
.multilineTextAlignment(.leading)
#if os(iOS)
.foregroundStyle(.red)
#else
.foregroundColor(.red)
Run Code Online (Sandbox Code Playgroud)
感谢您考虑我的问题
包索引是在 C++26 中引入的,我希望此功能能够对元编程产生重大影响,特别是对于索引包,否则需要解决方法。
由于包索引说明符的语法是:
typedef-name ... [ expression ]
Run Code Online (Sandbox Code Playgroud)
typedef-name是identifier或simple-template-id有了上述信息,是否允许:
template <typename>
using apply_t = bool;
// #1
template <typename... Args>
using A = apply_t<Args>...[0];
// can be reworked with: apply_t<Args...[0]>
// #2
template <template <typename...> typename... Temps>
using B = Temps<>...[0]
// no other way other than this because 'Temps...[0]<>' is not allowed yet (?)
Run Code Online (Sandbox Code Playgroud) 表格1 -Sales
| Country | State | City| Sales_Amt
Run Code Online (Sandbox Code Playgroud)
表 2 -Target
| Country | State | City| Target_Amt
Run Code Online (Sandbox Code Playgroud)
要求:
t.City IS NOT NULL,然后加入t.City = s.city;t.State IS NOT NULL,然后加入t.State = s.State;t.Country = s.CountrySELECT *
FROM Sales s
JOIN Target t ON s.city = t.city (implement the above conditions here)
Run Code Online (Sandbox Code Playgroud)
当 LHS 或 RHS 恒定时,我已经在 JOIN 中完成了 CASE WHEN 。但在这种情况下,LHS 和 RHS 都会根据条件检查而改变,我不确定如何实现这一点。
我有一个 [-8, 7] 范围内的整数数组,我想将它们写入二进制文件中。由于 4 位足以表示这些数字,因此我想将每两个元素压缩为一个 8 位整数,以便得到一个更小的文件。这是我到目前为止所拥有的:
#include <iostream>
#include <stdint.h>
int main()
{
int8_t a1{-1}, a2{1};
uint8_t a1_4bit = (((uint8_t)a1 & 0b10000000) >> 4) + (uint8_t)a1 & 0b00000111;
uint8_t a2_4bit = (((uint8_t)a2 & 0b10000000) >> 4) + (uint8_t)a2 & 0b00000111;
uint8_t compact_a = (a1_4bit << 4) + a2_4bit;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我在这里想做的是获取符号位和三个 LSB 位并将它们放在一起。但是当我尝试从中提取原始整数时,compact_a我得到的是7and1而不是-1and 1。我用来提取原始数字的代码是:
uint8_t a_re = compact_a/16 ;
uint8_t a_im = compact_a%16 ;
a_re = a_re << …Run Code Online (Sandbox Code Playgroud) 在 SBCL REPL 中,为什么输入的'(nil . nil)计算结果为(nil)而不仅仅是nil?
如果空列表是 cons 单元的两个“元素”所在的列表nil,为什么它们不一样?
我对此的假设是 SBCL 做出以下评估:
(car '()) => nil
(cdr '()) => nil
(car '(nil . nil)) => nil
(cdr '(nil . nil)) => nil
Run Code Online (Sandbox Code Playgroud)
但是:
'() => nil
'(nil . nil) => (nil)
Run Code Online (Sandbox Code Playgroud) 如果使用 CommonJS 模块,使用 setImmediate 调用 setTimeout 会出现不可预测的行为。但如果切换到ESM(package.json中的“type”:“module”),它总是会在setTimeout之前执行setImmediate。
setTimeout(() => {
console.log('timeout');
}, 0);
setImmediate(() => {
console.log('immediate');
});
Run Code Online (Sandbox Code Playgroud)
为什么会出现这种情况?这与 ESM 模块异步加载有关吗?
根据文档,当我跑步时git init,“将创建一个没有任何提交的初始分支”。但是当我运行git branch查看所有本地分支时,主/主分支不会出现。我想知道这是为什么。
另外,假设我在 main 的基础上创建了一个分支。所以在 init 之后,我做了一个git checkout -b myBranch. 考虑到还没有提交,这个分支现在指向哪里?它是否具有与 main 相同的指针值(即可能是某个空值),或者它实际上指向主分支本身?在这种情况下,当我从 myBranch 创建提交时,myBranch 现在是否指向该提交并仍然以某种方式引用 main ?
我对 Delphi 并不陌生,但对使用线程不熟悉。我正在开发一个需要查询多个服务器以获取数据的项目,我想我会尝试使用线程来实现它。其想法是创建一个专用线程来向每个远程服务器发送和处理查询,然后使用主程序来组合和处理从线程返回的收集数据。我找到了几个展示如何启动多个线程的示例,它们似乎都是使用“for”循环来完成的。我在项目中实现了相同的方法,但很失望地发现该方法仍然等待每个线程完成才能启动下一个线程。我希望能够同时启动所有线程,并等待它们收集请求的数据并返回它,然后处理它。推荐的方法是什么?这是简化的代码,说明了“不同时运行”的问题:
unit threads2;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, support, Vcl.StdCtrls, Vcl.ExtCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TMyThread = Class(TThread)
private
fnumber : longint;
fLog:tstrings;
fExecutionTime:TDateTime;
fiLimit: longint;
public
constructor Create(createsuspended: boolean; iLimit:integer);
procedure Execute(); override;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
constructor TMyThread.Create(createsuspended: boolean; ilimit:longint);
begin
inherited …Run Code Online (Sandbox Code Playgroud) pod install我目前正在尝试在 React Native 版本 0.73 中启动一个项目,但是当我在 iOS 目录中启动时遇到问题,特别是在安装 Boost 版本 1.83.0 时。
(node:66063) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.\n(Use `node --trace-deprecation ...` to show where the warning was created)\nFramework build type is static library\n[Codegen] Generating ./build/generated/ios/React-Codegen.podspec.json\n[Codegen] generating an empty RCTThirdPartyFabricComponentsProvider\nAnalyzing dependencies\nFetching podspec for `DoubleConversion` from `../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec`\n[Codegen] Found FBReactNativeSpec\nFetching podspec for `RCT-Folly` from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`\n[Codegen] Found rncore\nFetching podspec for `boost` from `../node_modules/react-native/third-party-podspecs/boost.podspec`\nFetching podspec for `glog` from `../node_modules/react-native/third-party-podspecs/glog.podspec`\nFetching podspec for `hermes-engine` from `../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec`\n[Hermes] …Run Code Online (Sandbox Code Playgroud) c++ ×3
node.js ×2
boost ×1
c++26 ×1
case ×1
cocoapods ×1
common-lisp ×1
commonjs ×1
delphi ×1
es6-modules ×1
event-loop ×1
git ×1
ios ×1
javascript ×1
join ×1
lisp ×1
npm ×1
parameters ×1
react-native ×1
sbcl ×1
sql ×1
swift ×1
swiftui ×1