我正在编写一个自定义插件,它将一些数据添加到 Java 项目的清单中。
它看起来像这样:
package com.example.gradle
import org.gradle.api.Plugin
import org.gradle.api.Project
public class ExamplePlugin implements Plugin<Project> {
def apply(Project project) {
project.jar() {
manifest {
attributes 'buildServer': checkIfIsBuildServer()
attributes 'personalBuild': checkIfIsPersonalBuild()
}
}
}
def checkIfIsBuildServer() {
return 'some result'
}
def checkIfIsPersonalBuild() {
return 'some result'
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试将其应用到某个项目时,出现错误:
Could not find method jar() for arguments [com.example.gradle.ExamplePlugin$_apply_closure1@411e4f5e] on project ':SomeProject' of type org.gradle.api.Project.
Run Code Online (Sandbox Code Playgroud)
我有理由确信这是一些缺失的导入。我不知道如何确定它应该是什么导入。
我试图以一种项目使用由另一种构建的文件的方式配置两个Gradle项目。第一个项目由添加到第二includeBuild个项目,并且在第二个项目中将文件定义为依赖项。
testAsettings.gradle:
rootProject.name = 'testA'
Run Code Online (Sandbox Code Playgroud)
build.gradle:
group = 'org.test'
version = '0.0.0.1_test'
task someZip (type: Zip) {
from './settings.gradle'
archiveName = 'xxx.zip'
destinationDir = file("${buildDir}/test")
}
artifacts {
//TODO add something here?
}
Run Code Online (Sandbox Code Playgroud)
testBsettings.gradle:
rootProject.name = 'testB'
if (System.getenv('LOCAL_COMPILATION') == 'true') {
includeBuild '../testA'
}
Run Code Online (Sandbox Code Playgroud)
build.gradle:
if (System.getenv('LOCAL_COMPILATION') != 'true') {
repositories {
maven { url '192.168.1.100' }
}
}
configurations {
magic
}
dependencies {
magic 'org.test:xxx:0.0.0.+@zip' …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个重载方法,仅当调用它的对象是非常量并且参数中传递的迭代器是非常量时才返回非常量结果。(可以将其视为标准方法begin(),并且begin() const还采用迭代器参数。)
我为普通迭代器制作了一个版本,没有任何问题。但是,由于某种原因,当我尝试对反向迭代器执行相同操作时,我收到有关不明确函数调用的编译错误。
这是一个最小的例子:
#include <vector>
class Foo
{
public:
void bar(std::vector<int>::iterator x) {}
void bar(std::vector<int>::const_iterator x) const {}
void baz(std::vector<int>::reverse_iterator x) {}
void baz(std::vector<int>::const_reverse_iterator x) const {}
};
int main()
{
std::vector<int> v;
Foo foo;
foo.bar(v.cbegin()); // OK
foo.baz(v.crbegin()); // ambiguous
}
Run Code Online (Sandbox Code Playgroud)
由于某种原因,如果我const从第二种方法中删除它,它就会编译baz。它也适用于 C++20,但目前我无法使用该版本。
如何使该函数baz以与该函数类似的方式工作bar?
我需要创建一个包含范围内所有值的数组。创建后我无法设置值,因为数组必须是 constexpr。
template<int FIRST, int LAST>
struct Foo
{
static constexpr int array[LAST - FIRST + 1] = ???;
};
Run Code Online (Sandbox Code Playgroud)
举个例子 Foo<3, 7>::array;
应该相当于static constexpr int array[5] = {3, 4, 5, 6, 7};.
甚至有可能吗?
std::frexp是一个从浮点变量中删除指数并将其放入exp类型变量中的函数int。int无论指数真正需要多少位,它都会根据链接页面使用:
如果要存储的值
*exp超出 的范围int,则行为未指定。
那么,如何检查“是否超出”*exp的范围呢?int
我正在考虑static_assert在我的代码中添加 a 来比较FLT_MIN_EXP&FLT_MAX_EXP与INT_MIN&INT_MAX。但是,我担心会犯一个相差一的错误,因为我不完全理解这些常量的描述。
FLT_MIN_EXP:
最小负整数,使得 FLT_RADIX 乘以比该整数小一倍的幂是归一化的
float...
FLT_MAX_EXP:
最大正整数,使得 FLT_RADIX 乘以该整数减一的幂是可表示的有限
float...
(我已经static_assert(FLT_RADIX == 2);在代码中包含了,所以在我的例子中基数等于 10 不是问题。)
如果我有一个迭代器指向 STL 容器中的一个元素,并且我用迭代器移动了该元素,那么标准是否保证迭代器仍然有效?我可以将它与容器的方法一起使用吗container::erase?
容器是连续容器(例如 )vector还是非连续容器(例如 )也很重要吗list?
std::list<std::string> l{"a", "b", "c"};
auto iter = l.begin();
auto s = std::move(*iter);
l.erase(iter); // <----- is it valid to erase it, whose underlying element has been removed?
Run Code Online (Sandbox Code Playgroud)