/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * 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 /** * C++ Core Guideline's not_null PtrT>. * * not_null holds a pointer-like type PtrT which is not nullptr. * * not_null is a drop-in replacement for T* (as long as it's never null). * Specializations not_null_unique_ptr and not_null_shared_ptr are * drop-in replacements for unique_ptr and shared_ptr, respecitively. * * Example: * void foo(not_null nnpi) { * *nnpi = 7; // Safe, since `nnpi` is not null. * } * * void bar(not_null_shared_ptr nnspi) { * foo(nnsp.get()); * } * * Notes: * - Constructing a not_null from a nullptr-equivalent argument throws * a std::invalid_argument exception. * - Cannot be used after move. * - In debug mode, not_null checks that it is not null on all accesses, * since use-after-move can cause the underlying PtrT to be null. */ #include #include #include #include #include #include namespace folly { namespace detail { template struct is_not_null; template struct is_not_null_convertible; template struct is_not_null_nothrow_constructible; template struct is_not_null_castable; template struct is_not_null_move_castable; template class> struct check_constraint_if_not {}; template