C++20 の新機能 : constexpr関係追加#20
Merged
Reputeless merged 6 commits intocppmap:masterfrom May 23, 2019
onihusube:master
Merged
Conversation
Member
|
ありがとうございます。確認中です。 c331258#diff-d21ab1223d831e3533f251ff5bbb105aR322 の {
constexpr int* nullp = nullptr;
constexpr auto&& t = typeid(nullp); //例外を投げるため定数実行できない
}では例外を投げないので、 #include <typeinfo>
struct Cpp
{
virtual ~Cpp() = default;
};
int main()
{
constexpr Cpp* pCpp = nullptr;
constexpr auto& cpptype = typeid(*pCpp); // error: 例外 std::bad_typeid を投げるため constexpr 不可
}に修正します。 struct Cpp
{
virtual int version() const = 0;
};
struct Cpp17 : Cpp
{
constexpr int version() const override
{
return 17;
}
};
struct Cpp20 : Cpp
{
constexpr int version() const override
{
return 20;
}
};
constexpr int GetVersion(const Cpp& a)
{
return a.version();
}
int main()
{
constexpr Cpp17 cpp17;
constexpr Cpp20 cpp20;
static_assert(GetVersion(cpp17) == 17);
static_assert(GetVersion(cpp20) == 20);
}また、c331258#diff-d21ab1223d831e3533f251ff5bbb105aR253 |
Contributor
Author
|
すいません、 |
Contributor
Author
|
直しました |
Member
|
Merged. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
constexpr関係のC++20新機能を書いてみました。
文章やコード内容はよしなになさってください!