Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add operator bool to modint#169

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
szdytom wants to merge2 commits intoatcoder:master
base:master
Choose a base branch
Loading
fromszdytom:master
Open

Conversation

szdytom
Copy link

It can be useful if you want something like:

mint x;// ...if (x)  do_sth(x);

Signed-off-by: szdytom <szdytom@qq.com>
@mizar
Copy link

95a6273
Strange to convert zero value totrue.

For conversion rules between bool and int types in the C++ language,

https://timsong-cpp.github.io/cppwp/n4659/conv.prom#6

A prvalue of typebool can be converted to a prvalue of typeint, withfalse becoming zero andtrue becoming one.

https://timsong-cpp.github.io/cppwp/n4659/conv.bool#1

A prvalue of arithmetic, unscoped enumeration, pointer, or pointer to member type can be converted to a prvalue of typebool. A zero value, null pointer value, or null member pointer value is converted tofalse; any other value is converted totrue. Fordirect-initialization, a prvalue of typestd​::​nullptr_­t can be converted to a prvalue of typebool; the resulting value isfalse.

TumoiYorozu reacted with thumbs up emoji

Copy link

@yaito3014yaito3014 left a comment

Choose a reason for hiding this comment

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

it is preferred to make conversion function explicit unless any reason not to do so.

@szdytom
Copy link
Author

it is preferred to make conversion function explicit unless any reason not to do so.

This is the place where we need implicit conversion. no one wants to writeif ((bool)x) { ... } anyway.

@yaito3014
Copy link

it is preferred to make conversion function explicit unless any reason not to do so.

This is the place where we need implicit conversion. no one wants to writeif ((bool)x) { ... } anyway.

You can writeif (x) { ... } even if the conversion operator to bool is marked as explicit.

cf.https://en.cppreference.com/w/cpp/language/implicit_conversion#Contextual_conversions

@TumoiYorozu
Copy link
Contributor

TumoiYorozu commentedSep 8, 2024
edited
Loading

This repositorydoes not accept requests for new features.

For now, we are not planning to add new features

In this case, I don't think it's necessary because you can add a custom bool cast as shown below:

#include<atcoder/modint>#include<bits/stdc++.h>structmint :publicmodint998244353 {using static_modint::static_modint;mint(modint998244353  m) : modint998244353 (m) {}operatorbool()const {returnval() !=0; }};intmain() {    mintm(123);if (m) {puts("not zero");    }else {puts("zero");    }}

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@yaito3014yaito3014yaito3014 left review comments

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@szdytom@mizar@yaito3014@TumoiYorozu

[8]ページ先頭

©2009-2025 Movatter.jp