2 * Copyright 2016 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <glog/logging.h>
20 #include <folly/Portability.h>
24 template <typename T, bool Debug>
25 class ConditionallyExistent;
28 class ConditionallyExistent<T, false> {
30 static constexpr bool present() { return false; }
31 explicit ConditionallyExistent(const T&) {}
32 explicit ConditionallyExistent(T&&) {}
33 ConditionallyExistent(const ConditionallyExistent&) = delete;
34 ConditionallyExistent(ConditionallyExistent&&) = delete;
35 ConditionallyExistent& operator=(const ConditionallyExistent&) = delete;
36 ConditionallyExistent& operator=(ConditionallyExistent&&) = delete;
38 void with(const F&&) {}
42 class ConditionallyExistent<T, true> {
44 static constexpr bool present() { return true; }
45 explicit ConditionallyExistent(const T& v) : value_(v) {}
46 explicit ConditionallyExistent(T&& v) : value_(std::move(v)) {}
47 ConditionallyExistent(const ConditionallyExistent&) = delete;
48 ConditionallyExistent(ConditionallyExistent&&) = delete;
49 ConditionallyExistent& operator=(const ConditionallyExistent&) = delete;
50 ConditionallyExistent& operator=(ConditionallyExistent&&) = delete;
61 using ExistentIfDebug = ConditionallyExistent<T, kIsDebug>;