小编Key*_*rys的帖子

Parse ISO 8601 time duration using Go (for instance PT90M)

有没有什么简单的方法可以将 ISO 8601 字符串持续时间 ( P(n)Y(n)M(n)DT(n)H(n)M(n)S) 转换为time.Duration

来自维基百科关于 ISO 8601 的持续时间

例如,“P3Y6M4DT12H30M5S”代表“三年六个月四天十二小时三十分五秒”的持续时间。

duration iso8601 go

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

向量的通用参考

我想使用带向量的通用引用.

template<typename T>
    void foo(T&& v)
    {
        for(typename T::iterator i = v.begin(); i != v.end(); i++)
        {
            std::cout << *i << std::endl;
        }
    }

int main()
{
    std::vector v = {0,5,4,3};
    foo(std::move(v));
    foo(v); //compiler error
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

但是当我使用foo函数v的参数(没有std :: move)时会导致编译错误.

我认为在这两种情况下,通用引用都应该有效.

错误:

prog.cc: In instantiation of 'void foo(T&&) [with T = std::vector<int, std::allocator<int> >&]':
prog.cc:25:10: required from here prog.cc:16:30: error: 'std::vector<int, std::allocator<int> >&' is not a class, struct, or union type 16 | for(typename T::iterator i = v.begin(); i …
Run Code Online (Sandbox Code Playgroud)

c++

4
推荐指数
2
解决办法
140
查看次数

弹簧 - 千分尺 + opentelemetry-exporter-otlp

是否可以配置千分尺在春季将跟踪信息发送到otel容器?

我轻松配置了向 Zipkin 和 Wavefront 发送跨度: https://docs.spring.io/spring-boot/docs/3.1.0-SNAPSHOT/reference/htmlsingle/#actuator.micrometer-tracing.tracers但没有关于导出的内容到酒店。

Micrometer 文档也没有提到将跨度导出到 otel 容器https://micrometer.io/docs/tracing#_using_micrometer_tracing_directly

spring boot 3 需要在 pom.xml 中包含哪些依赖项才能成功运行

spring spring-boot micrometer

4
推荐指数
1
解决办法
4916
查看次数

当member是unique_ptr时删除了复制构造函数

这段代码工作正常:

class Test
{
    int* ptr = new int(10);
};

int main()
{       
     Test o;
     Test t = o;
}
Run Code Online (Sandbox Code Playgroud)

但是当我们使用unique_ptr而不是raw ptr时,我们会收到一个错误:

error: use of deleted function 'Test::Test(const Test&)'
Run Code Online (Sandbox Code Playgroud)

示例代码:

class Test
{
     std::unique_ptr<int> ptr = std::make_unique<int>(1);
};

int main()
{       
     Test o;
     Test t = o;
}
Run Code Online (Sandbox Code Playgroud)

到底是怎么回事?

c++

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

使用 Golang 获取用户名和域名

有没有办法使用golang获取Windows用户名?我也想要一个域名。在我的情况下域是“WORKGROUP”

cmd -> 系统信息:

在此处输入图片说明

windows go

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

推迟当前值

我想使用 defer 和函数参数中参数的最新值来调用该函数。我怀疑运行这段代码:

package main

import (
    "fmt"
)

func main() {
    s := "ABC"
    
    defer fmt.Println(s)
    s = "DEF"
}
Run Code Online (Sandbox Code Playgroud)

我会得到DEF。但我得到的是ABC。有什么办法可以得到DEF吗?

go

-2
推荐指数
1
解决办法
611
查看次数

标签 统计

go ×3

c++ ×2

duration ×1

iso8601 ×1

micrometer ×1

spring ×1

spring-boot ×1

windows ×1