小编gsf*_*gsf的帖子

禁用maven下载进度指示

在我们公司的CI机器中,maven本地存储库在每次构建之前被清除.结果我的构建日志总是有一堆像这样的噪音

Downloading: http://.../artifactory/repo/com/codahale/metrics/metrics-core/3.0.1/metrics-core-3.0.1.jar
4/2122 KB   
8/2122 KB   
12/2122 KB   
16/2122 KB   
18/2122 KB   
18/2122 KB   4/480 KB   
18/2122 KB   8/480 KB   
18/2122 KB   12/480 KB   
18/2122 KB   16/480 KB   
18/2122 KB   16/480 KB   4/1181 KB   
18/2122 KB   16/480 KB   8/1181 KB   
18/2122 KB   16/480 KB   12/1181 KB
Run Code Online (Sandbox Code Playgroud)

有没有选项我可以禁用下载进度指示?

maven

144
推荐指数
4
解决办法
3万
查看次数

golang排序切片升序或降序

我需要对来自第三方软件包的类型进行排序.根据某些条件,订单必须是升序或降序.

我提出的解决方案是:

type fooAscending []foo

func (v fooAscending) Len() int           { return len(v) }
func (v fooAscending) Swap(i, j int)      { v[i], v[j] = v[j], v[i] }
func (v fooAscending) Less(i, j int) bool { return v[i].Amount < v[j].Amount }

type fooDescending []foo

func (v fooDescending) Len() int           { return len(v) }
func (v fooDescending) Swap(i, j int)      { v[i], v[j] = v[j], v[i] }
func (v fooDescending) Less(i, j int) bool { return v[i].Amount > v[j].Amount }

if someCondition …
Run Code Online (Sandbox Code Playgroud)

sorting go

13
推荐指数
6
解决办法
2万
查看次数

我如何将lambda表达式作为参数传递给c ++模板

我有一个接受函数作为参数的模板.

当我尝试传递lambda表达式时,它不会编译.

typedef int (*func)(int a);
template <func foo>
int function(int a)
{
    foo(a);
}

int test(int a)
{
    return a;
}

int main()
{
    function<test>(1);   // ---> this is ok

    auto lambda = [](int a) -> int { return a; };
    function<lambda>(1); // ---> this is wrong, why?

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我错过了什么?

c++ lambda templates

10
推荐指数
3
解决办法
8431
查看次数

std :: string在安全的地方截断utf-8的最佳方法

我在std :: string中有一个有效的utf-8编码字符串.我有字节限制.我想截断字符串并添加... at MAX_SIZE - 3 - x- where x这个值将阻止utf-8字符被剪切.

是否有可以x根据MAX_SIZE 确定的函数而无需从字符串的开头开始?

c++ string utf-8

8
推荐指数
1
解决办法
1220
查看次数

提升变体简单调用常用方法

我有两个指针,只能设置其中一个,所以我正在考虑使用boost :: variant,比如说:boost::variant<shared_ptr<Type1> shared_ptr<Type2>>.类型1和类型2不同,但它们共享一些功能.例如,Thay都有这种方法IsUnique.

如果我有代码来检查初始化:

ASSERT(type1 != nullptr || type2 != nullptr);
ASSERT(type1 == nullptr || type2 == nullptr);
ASSERT(type1 == nullptr || type1->IsUnique());
ASSERT(type2 == nullptr || type2->IsUnique());
Run Code Online (Sandbox Code Playgroud)

我希望能够用尽可能接近的东西替换它:

ASSERT(variant != nullptr);
ASSERT(variant->IsUnique());
Run Code Online (Sandbox Code Playgroud)

但似乎我必须定义访问者,切换类型.

我是否会遗漏某些内容,是否有模板或某些内容可以让我将某些内容应用于当前类型的内容?它可能是c ++ 14.

c++ boost boost-variant

8
推荐指数
1
解决办法
435
查看次数

html从剪贴板副本中排除文本

我在另一个范围内有一个跨度.我想允许用户能够从父跨度中选择文本,而不是从子跨度中选择文本.

注意:( user-select家庭)不起作用.它阻止选择在此区域中开始或结束,但如果我使用父跨度中的文本中的选择将其包围,则文本仍在最终剪贴板结果中.

例如:

<head>
<style>
  .hole-hint {
    display: inline-block;
    position: absolute;
    bottom: 45%;
    font-size: 12px;
    color:rgb(255, 0, 0);
    background-color:rgba(255, 225, 225, 0.5);
    z-index:1;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    -o-user-select: none;
    user-select: none;
  }
  .hole {
    padding-top: 7px;
    position: relative;
    background-color:#EEEEEE;
  }
  </style>
  </head>
  <body>
      <span> this is the parent text<span class="hole"><span class="hole-hint">no copy</span></span>and this is text on the other side   </span>
  </body>
  </html>
Run Code Online (Sandbox Code Playgroud)

html css clipboard

6
推荐指数
1
解决办法
1258
查看次数

用模板参数除以零

我有一个模板

template<size_t N>
class Foo {
    int bar(int a) {
        if (N == 0)
            return 0;
        return a / N;
    }
 }
Run Code Online (Sandbox Code Playgroud)

当我用0实例化它

Foo<0> bar;
Run Code Online (Sandbox Code Playgroud)

gcc太聪明了,在编译时报告除零

我试过了

class Foo<size_t N> {
    template<size_t M>
    int bar(int a) {
        return a / N;
    }

    template<>
    int bar<0>(int a) {
        return 0;
    }
 };
Run Code Online (Sandbox Code Playgroud)

但这给了我错误:

错误:非命名空间范围'class Foo'中的显式特化错误:主模板声明中的template-id'bar <0>'

我有什么想法可以解决/解决这个问题?

c++ templates

6
推荐指数
2
解决办法
490
查看次数

C++使用RAII和析构函数抛出

假设我有RAII课程:

class Raii {
    Raii() {};
    ~Raii() { 
        if (<something>) throw std::exception();
    }
};
Run Code Online (Sandbox Code Playgroud)

如果我有这个功能:

void foo() {
    Raii raii;    

    if (something) {
       throw std::exception();
    }
} 
Run Code Online (Sandbox Code Playgroud)

这很糟糕,因为在清理第一个异常时我们可以再次抛出,这将终止进程.

我的问题是 - 对于清理可能抛出的代码使用raii有什么好的模式?

例如这是好还是坏 - 为什么?

class Raii {
    Raii() {};
    ~Raii() {
        try {
           if (<something>) throw std::exception();
        }
        catch (...) {
           if (!std::uncaught_exception())
               throw;
        }
    }
};
Run Code Online (Sandbox Code Playgroud)

请注意,Raii对象始终是堆栈分配的对象 - 这不是析构函数问题的一般抛出.

c++ exception raii

6
推荐指数
2
解决办法
831
查看次数

使用 tee 打印到输出时为每一行添加前缀

我有这样的命令

command | tee /dev/tty | grep ...
Run Code Online (Sandbox Code Playgroud)

那说打印

hello
world
Run Code Online (Sandbox Code Playgroud)

我想改变这一点,以便命令输出中的每一行都带有前缀,在输出中或看起来像:

# hello
# world
Run Code Online (Sandbox Code Playgroud)

bash shell

5
推荐指数
1
解决办法
1678
查看次数

扩展变量名中的宏值

我有

#define MACRO foo

#define Code(m) \
    m##Bar

Code(MACRO)
Run Code Online (Sandbox Code Playgroud)

我希望将其解析为 fooBar,但它被解析为 MACROBar。

我需要更改宏以通过其值而不是其名称来解析。

c c-preprocessor

5
推荐指数
1
解决办法
2956
查看次数

标签 统计

c++ ×5

templates ×2

bash ×1

boost ×1

boost-variant ×1

c ×1

c-preprocessor ×1

clipboard ×1

css ×1

exception ×1

go ×1

html ×1

lambda ×1

maven ×1

raii ×1

shell ×1

sorting ×1

string ×1

utf-8 ×1