Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maybe: add JUST_MSG and CHECK_JUST_MSG #5904

Merged
merged 16 commits into from Aug 18, 2021

Conversation

PragmaTwice
Copy link
Contributor

@PragmaTwice PragmaTwice commented Aug 16, 2021

Close #5855

Usage:

int x = ...;
auto val = JUST_MSG(f(), "error: value ", x, " is too large");
auto val = JUST_MSG((g<X, Y>()), "error: value ", x, " is too large");

Copy link
Contributor

@lixinqi lixinqi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

添加一点单测,那其实也是告诉别人怎么用。
单测脚本的写法可以参考common/range_test.cpp

@daquexian
Copy link
Contributor

daquexian commented Aug 16, 2021

有没有可能用一些 trick 做到不额外引入 JUST_MSG,维持 JUST 的现有用法,并同时支持 msg。思路是 ”逗号应该被当作参数分隔符“ 和 ”逗号不出现在 <>、() 内“ 应该是等价的,在编译期对字符串常量 OF_PP_STRINGIZE((__VA_ARGS__)) 做分析,就能正确的分割参数。不知道这个思路是不是有可行性

@PragmaTwice
Copy link
Contributor Author

在预处理期不太能有方法分辨出 < 是模板参数的开始还是小于号

@daquexian
Copy link
Contributor

在预处理期不太能有方法分辨出 < 是模板参数的开始还是小于号

好的,我先放弃我的想法了

@PragmaTwice
Copy link
Contributor Author

PragmaTwice commented Aug 17, 2021

添加一点单测,那其实也是告诉别人怎么用。

Done

oneflow/core/common/maybe_test.cpp Outdated Show resolved Hide resolved
oneflow/core/common/maybe_test.cpp Outdated Show resolved Hide resolved
oneflow/core/common/maybe_test.cpp Show resolved Hide resolved
@oneflow-ci-bot oneflow-ci-bot self-requested a review August 18, 2021 11:28
@oneflow-ci-bot oneflow-ci-bot requested review from oneflow-ci-bot and removed request for oneflow-ci-bot August 18, 2021 11:34
@oneflow-ci-bot oneflow-ci-bot self-requested a review August 18, 2021 12:35
@oneflow-ci-bot oneflow-ci-bot requested review from oneflow-ci-bot and removed request for oneflow-ci-bot August 18, 2021 14:06
@oneflow-ci-bot oneflow-ci-bot self-requested a review August 18, 2021 15:29
@oneflow-ci-bot oneflow-ci-bot requested review from oneflow-ci-bot and removed request for oneflow-ci-bot August 18, 2021 17:10
@oneflow-ci-bot oneflow-ci-bot self-requested a review August 18, 2021 19:27
@oneflow-ci-bot oneflow-ci-bot requested review from oneflow-ci-bot and removed request for oneflow-ci-bot August 18, 2021 20:37
@oneflow-ci-bot oneflow-ci-bot requested review from oneflow-ci-bot and removed request for oneflow-ci-bot August 18, 2021 21:35
@oneflow-ci-bot oneflow-ci-bot merged commit c82e6db into Oneflow-Inc:master Aug 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support JUST(may_expr, error_msg)
4 participants