Skip to content

Commit

Permalink
*: introduce not_null as a submodule (#8802)
Browse files Browse the repository at this point in the history
close #8933
  • Loading branch information
CalvinNeo authored Apr 18, 2024
1 parent b454a90 commit 5cba983
Show file tree
Hide file tree
Showing 5 changed files with 413 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,6 @@
[submodule "contrib/simdjson"]
path = contrib/simdjson
url = https://github.com/simdjson/simdjson.git
[submodule "contrib/not_null"]
path = contrib/not_null
url = https://github.com/bitwizeshift/not_null.git
1 change: 1 addition & 0 deletions contrib/not_null
Submodule not_null added at 95a3e8
1 change: 1 addition & 0 deletions dbms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ else ()
install (TARGETS dbms LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT tiflash)
endif ()

target_include_directories(dbms PUBLIC ${TiFlash_SOURCE_DIR}/contrib/not_null/include)
target_include_directories(dbms PUBLIC "${TIFLASH_PROXY_INCLUDE_DIR}")

if (CMAKE_BUILD_TYPE_UC STREQUAL "RELEASE" OR CMAKE_BUILD_TYPE_UC STREQUAL "RELWITHDEBINFO" OR CMAKE_BUILD_TYPE_UC STREQUAL "MINSIZEREL")
Expand Down
54 changes: 54 additions & 0 deletions dbms/src/Common/NotNull.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2024 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include <Common/Exception.h>

#include <memory>
#include <not_null.hpp>

namespace DB
{

template <typename T>
using NotNull = cpp::bitwizeshift::not_null<T>;

// It involves an extra check when constructing,
// if we can't tell if `ptr` is nullptr at compile time.
template <class T>
auto newNotNull(T && ptr)
{
return cpp::bitwizeshift::check_not_null(std::move(ptr));
}

template <class T, class... Args>
auto makeNotNullShared(Args &&... args)
{
return cpp::bitwizeshift::assume_not_null(std::make_shared<T>(std::forward<Args>(args)...));
}

template <class T, class... Args>
auto makeNotNullUnique(Args &&... args)
{
return cpp::bitwizeshift::assume_not_null(std::make_unique<T>(std::forward<Args>(args)...));
}

template <typename T>
using NotNullShared = cpp::bitwizeshift::not_null<std::shared_ptr<T>>;

template <typename T>
using NotNullUnique = cpp::bitwizeshift::not_null<std::unique_ptr<T>>;

}; // namespace DB
Loading

0 comments on commit 5cba983

Please sign in to comment.