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:
Mark Olesen
2020-05-29 12:49:48 +02:00
parent e3367dbdc1
commit 1d2391e0b4
2 changed files with 28 additions and 13 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2014 OpenFOAM Foundation Copyright (C) 2014 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd. Copyright (C) 2019-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -47,9 +47,8 @@ class SimpleClass
{ {
public: public:
//- Null constructor //- Default construct
SimpleClass() SimpleClass() {}
{}
}; };
@ -149,6 +148,12 @@ int main()
printInfo(pointField::null()); 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; Info<< nl;
return 0; return 0;

View File

@ -105,31 +105,41 @@ public:
} }
//- Zero valued integer content //- Zero valued integer content
inline unsigned long value() const inline constexpr unsigned long value() const
{ {
return data_[0].val; return 0;
} }
//- No elements //- No elements
inline bool empty() const inline constexpr bool empty() const
{ {
return true; return true;
} }
//- Zero elements //- Zero elements
inline label size() const inline constexpr label size() const
{ {
return 0; return 0;
} }
//- No-op method (for HashTable replacement) //- No-op method (for HashTable replacement)
inline const NullObject& toc() const inline constexpr const NullObject& toc() const
{ {
return *this; return *this;
} }
//- No-op method (for HashTable replacement) //- 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; return *this;
} }
@ -146,13 +156,13 @@ extern const NullObject* nullObjectPtr;
// IOstream Operators // IOstream Operators
//- Read from Istream consumes no content. //- Read from Istream consumes no content
inline Istream& operator>>(Istream& is, NullObject&) noexcept inline Istream& operator>>(Istream& is, const NullObject&) noexcept
{ {
return is; return is;
} }
//- Write to Ostream emits no content. //- Write to Ostream emits no content
inline Ostream& operator<<(Ostream& os, const NullObject&) noexcept inline Ostream& operator<<(Ostream& os, const NullObject&) noexcept
{ {
return os; return os;