Files
nitro/packages/react-native-nitro-modules/cpp/core/Null.hpp
T
Marc RousavyandGitHub 0c4306cbd7 feat: Add explicit null type (#1032)
* feat: Add explicit `null` type

* Handle the cases

* Use NullType instead of `std::monostate`

* null is now variant! nice

* fix: Add missing imports

* fix: Fix podspec

* whoops now its fixed

* we're getting there...

* it builds on Android!

* fix: Add monostate back

* fix: Fix JNull lookup

* fix: Fix Swift build

* feat: Add tests for `null` type

* remove `UndefinedType`

* Now iOS builds???

* Nulls docs

* fix: Build with Xcode 26.1

* Revert "fix: Build with Xcode 26.1"

This reverts commit 41d1efea7a.
2025-11-10 22:31:22 +01:00

43 lines
829 B
C++

//
// Created by Marc Rousavy on 30.07.24.
//
#pragma once
#include "NitroDefines.hpp"
#include <functional>
#include <type_traits>
namespace margelo::nitro {
/**
* Represents the type of `null` - which should always be a singleton.
*/
enum class NullType { null };
/**
* Represents an explicit `null` from JS.
* This is a singleton.
*/
inline constexpr NullType null = NullType::null;
// Equality and ordering: all instances are equal
constexpr bool operator==(NullType, NullType) noexcept {
return true;
}
constexpr bool operator!=(NullType, NullType) noexcept {
return false;
}
} // namespace margelo::nitro
// Makes nitro::Null hashable
namespace std {
template <>
struct hash<margelo::nitro::NullType> {
size_t operator()(margelo::nitro::NullType) const noexcept {
return 0;
}
};
} // namespace std