make extent_hooks static.
[folly.git] / folly / experimental / CodingDetail.h
1 /*
2  * Copyright 2017 Facebook, Inc.
3  *
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
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 /**
18  * @author Giuseppe Ottaviano <ott@fb.com>
19  *
20  * Shared utils for BitVectorCoding.h and EliasFanoCoding.h.
21  */
22
23 #pragma once
24
25 namespace folly {
26 namespace compression {
27 namespace detail {
28
29 /**
30  * Helpers to store pointers to forward and skip pointer arrays only
31  * if they are used, that is, the quantum is nonzero. If it is 0, the
32  * class is empty, and the member is static to keep the syntax valid,
33  * thus it will take no space in a derived class thanks to empty base
34  * class optimization.
35  */
36 template <size_t>
37 class ForwardPointers {
38  protected:
39   explicit ForwardPointers(const unsigned char* ptr) : forwardPointers_(ptr) {}
40   const unsigned char* const forwardPointers_;
41 };
42 template <>
43 class ForwardPointers<0> {
44  protected:
45   explicit ForwardPointers(const unsigned char*) {}
46   constexpr static const unsigned char* const forwardPointers_{};
47 };
48
49 template <size_t>
50 class SkipPointers {
51  protected:
52   explicit SkipPointers(const unsigned char* ptr) : skipPointers_(ptr) {}
53   const unsigned char* const skipPointers_;
54 };
55 template <>
56 class SkipPointers<0> {
57  protected:
58   explicit SkipPointers(const unsigned char*) {}
59   constexpr static const unsigned char* const skipPointers_{};
60 };
61 }
62 }
63 }