boostorg / boostorg/hana

Strange behavior of `hana::partial`

Open
#528 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
1.9k
Forks
225
PR merge metrics
No merged PRs in 30d

Description

Hello, and thank you for the excellent library! I found a strange behavior using `hana::partial` as shown in the following snippet:
```cpp
auto lambda = [](int& i) {
std::cout << i++ << " ";
std::cout << i << std::endl;
};
const int j = 0;
auto partial = hana::partial(lambda, j);
partial();
```
The above will print `0 1` and change the value of the constant variable `i`. Is this behavior expected? If I do not store the output of `hana::partial`, then the code does not compile as desired:
```cpp
auto lambda = [](int& i) {
std::cout << i++ << " ";
std::cout << i << std::endl;
};
const int j = 0;
hana::partial(lambda, j)(); // <= Error!
```

Contributor guide

Open the contributing guide

Research direction

Start at the hana::partial entry point and reproduce both snippets, including the mutation of the const argument and the direct temporary invocation error. Read the partial application and argument-storage semantics to determine the intended behavior; done means the behavior is clarified and the relevant case has a tested resolution.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.