小编Ang*_*ket的帖子

F# 中 printfn 函数的返回类型究竟是什么?

在这里查找了 printfn 的文档,它是这样说的:

printfn 格式

使用给定格式打印到标准输出,并添加换行符。

format : TextWriterFormat<'T> 格式化程序。

返回: 'T 格式化结果。

但是如果我在 FSI 中输入以下内容

> let v = printfn "Hello";;
Hello
val v : unit = ()
Run Code Online (Sandbox Code Playgroud)

它指出v( printfn 的返回值)的类型为unit

这似乎不一致,但我想我在这里遗漏了一些东西,所以有人可以帮我吗?

f#

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

Spring web安全:@EnableWebSecurity已经过时了吗?

在使用spring-boot-starter-security使用简单的Web应用程序测试Spring Boot(1.3.3)时:1.3.3:RELEASE我发现了以下行为:

为了覆盖默认的Spring Web安全配置,我提供了一个自定义Java配置类,如下所示:

@Configuration
// @EnableWebSecurity apparently obsolete ?
public class SecurityConfig extends WebSecurityConfigurerAdapter {


  @Override
  protected void configure(HttpSecurity http) throws Exception {
      // http security checking left out for brevity ...
  }


  @Override
  protected void configure(
              AuthenticationManagerBuilder auth) throws Exception {
      // user authentication left out for brevity ...
  }

}
Run Code Online (Sandbox Code Playgroud)

启动后,应用程序重定向到登录页面并正确检查用户名/密码是否提供了@EnableWebSecurity注释(如上例所示).这个背景中的这个注释是否已经过时了?如果是这样,为什么?

spring-security spring-boot

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

调用函数时没有调用构造函数

MyType同时定义了副本和移动ctor.执行以下代码段时(使用VS2015编译后):

template<typename T>
void f(T&& o) {
    // do something with o
}

int main() {
    MyType o{ 1, 2, 3 };
    f(o); // call of copy-constructor expected
    f(std::move(o)); // call of move-constructor expected
}
Run Code Online (Sandbox Code Playgroud)

我希望f在第二次调用之后第一次调用和移动构造函数之后调用复制构造函数f.但是在任何情况下都没有构造函数被调用.我怀疑这种行为是编译器优化,但我不确定可移植性或符合标准.

c++ move-semantics perfect-forwarding c++11 c++14

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

C++20:为什么范围适配器和范围不能组合在一个表达式中?

我正在看以下片段:

std::vector<int> elements{ 1,2,3 };
// this won't compile:
elements
    | std::views::filter([](auto i) { return i % 2 == 0; })
    | std::ranges::for_each([](auto e) {std::cout << e << std::endl; });
// but this compiles:
auto view  = 
elements
    | std::views::filter([](auto i) { return i % 2 == 0; });
std::ranges::for_each(view, [](auto e) {std::cout << e << std::endl; });
 
Run Code Online (Sandbox Code Playgroud)

我看不出范围适配器(视图)和范围算法通过管道运算符的组合无法编译的原因。std::ranges::dangling我想这与我的编译器(msvc 19.29)报告的返回类型有关for_each,但我不确定......

c++ c++20 std-ranges

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