Skip to content

[BUG] How to use std::function in pure cpp2 ? #711

Closed
@jituderaps

Description

@jituderaps

not able to use std::function in pure cpp2.
problem link: https://cpp2.godbolt.org/z/e6acYboTY

#include <functional>

fun: (x: int) -> int = 2 * x;

main: () -> i32 = {
    p_fun1: std::function<:(x: int) -> int> =  fun&;    // doesn't work
    // p_fun2: std::function<int(int)> = fun&;              // works fine

    std::cout << p_fun1(3);
}

command line : -DCMAKE_CXX_FLAGS="-std=c++23 -pedantic-errors -Wall -Wextra -Wconversion -Werror=unused-result" -GNinja -Wno-dev

Expected result : 6
Actual result :

example.cpp2(6,26): error: missing ';' at end of declaration or '=' at start of initializer (at '<')
example.cpp2(5,19): error: ill-formed initializer (at '{')
example.cpp2(5,1): error: unexpected text at end of Cpp2 code section (at 'main')
example.cpp2(2,0): error: parse failed for section starting here

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions