Skip to content

Commit 16ee53e

Browse files
committed
Hide the inherited members like spin() from cell and heptagon.
We don't want `c1->spin(d)` to compile, but we do want `c1->c().spin(d)` to compile. Make the CRTP inheritance private and make `->c()` the magic incantation to poke through that privateness.
1 parent e153bb5 commit 16ee53e

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

locations.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,11 @@ template<class T> struct walker;
127127
int gmod(int i, int j);
128128

129129
template<class CRTP, class T>
130-
class trailing_connection_table {
131-
132-
CRTP *crtp() { return static_cast<CRTP*>(this); }
130+
class connection_table_details {
131+
CRTP *crtp() {
132+
static_assert(std::is_base_of<connection_table_details, CRTP>::value, "");
133+
return static_cast<CRTP*>(this);
134+
}
133135
T **move_table() {
134136
static_assert(alignof(CRTP) >= alignof(T*), "");
135137
return (T **)(crtp() + 1);
@@ -139,13 +141,6 @@ class trailing_connection_table {
139141
}
140142

141143
public:
142-
static size_t tailored_alloc_size(int degree) {
143-
return sizeof(CRTP) + (degree * sizeof(T*)) + degree;
144-
}
145-
146-
trailing_connection_table& c() { return *this; }
147-
const trailing_connection_table& c() const { return *this; }
148-
149144
/** \brief for the edge d, set the `spin` and `mirror` attributes */
150145
void setspin(int d, int spin, bool mirror) {
151146
unsigned char& c = spin_table()[d];
@@ -183,6 +178,18 @@ class trailing_connection_table {
183178
}
184179
};
185180

181+
template<class CRTP, class T>
182+
class trailing_connection_table : private connection_table_details<CRTP, T> {
183+
public:
184+
friend class connection_table_details<CRTP, T>;
185+
186+
connection_table_details<CRTP, T>& c() { return *this; }
187+
188+
static size_t tailored_alloc_size(int degree) {
189+
return sizeof(CRTP) + (degree * sizeof(T*)) + degree;
190+
}
191+
};
192+
186193
/** \brief Allocate a class T with a connection_table, but with only `degree` connections.
187194
*
188195
* Also set yet unknown connections to NULL.

0 commit comments

Comments
 (0)