mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add swallow assignment to nullObject
- similar to the behaviour of std::ignore and consistent with the no input / no output nature of nullObject. Similarly accept a const reference for its Istream operator. - make most nullObject methods constexpr
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2014 OpenFOAM Foundation
|
||||
Copyright (C) 2019 OpenCFD Ltd.
|
||||
Copyright (C) 2019-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -47,9 +47,8 @@ class SimpleClass
|
||||
{
|
||||
public:
|
||||
|
||||
//- Null constructor
|
||||
SimpleClass()
|
||||
{}
|
||||
//- Default construct
|
||||
SimpleClass() {}
|
||||
};
|
||||
|
||||
|
||||
@ -149,6 +148,12 @@ int main()
|
||||
printInfo(pointField::null());
|
||||
}
|
||||
|
||||
// Test swallow assigment (like std::ignore)
|
||||
// Looks pretty ugly though!
|
||||
|
||||
NullObject::nullObject = "hello world";
|
||||
NullObject::nullObject = labelList({1, 2, 3});
|
||||
|
||||
Info<< nl;
|
||||
|
||||
return 0;
|
||||
|
||||
@ -105,31 +105,41 @@ public:
|
||||
}
|
||||
|
||||
//- Zero valued integer content
|
||||
inline unsigned long value() const
|
||||
inline constexpr unsigned long value() const
|
||||
{
|
||||
return data_[0].val;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//- No elements
|
||||
inline bool empty() const
|
||||
inline constexpr bool empty() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//- Zero elements
|
||||
inline label size() const
|
||||
inline constexpr label size() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//- No-op method (for HashTable replacement)
|
||||
inline const NullObject& toc() const
|
||||
inline constexpr const NullObject& toc() const
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
//- No-op method (for HashTable replacement)
|
||||
inline const NullObject& sortedToc() const
|
||||
inline constexpr const NullObject& sortedToc() const
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
// Member Operators
|
||||
|
||||
//- Swallow assignment (cf, std::ignore)
|
||||
template<class T>
|
||||
inline constexpr const NullObject& operator=(const T&) const
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
@ -146,13 +156,13 @@ extern const NullObject* nullObjectPtr;
|
||||
|
||||
// IOstream Operators
|
||||
|
||||
//- Read from Istream consumes no content.
|
||||
inline Istream& operator>>(Istream& is, NullObject&) noexcept
|
||||
//- Read from Istream consumes no content
|
||||
inline Istream& operator>>(Istream& is, const NullObject&) noexcept
|
||||
{
|
||||
return is;
|
||||
}
|
||||
|
||||
//- Write to Ostream emits no content.
|
||||
//- Write to Ostream emits no content
|
||||
inline Ostream& operator<<(Ostream& os, const NullObject&) noexcept
|
||||
{
|
||||
return os;
|
||||
|
||||
Reference in New Issue
Block a user