I want to write a concept Indexable meaning that a sequence either has begin/end that return RandomAccessIterator, or operator[] is defined and returns a value of non void type.
I used ideas from Stroustrup's article for the Sequence concept and augmented it with:
template <class T>
concept bool Indexable = Sequence<T> || requires(T t, size_t n) {
{ t[n] } -> NotVoid;
};
It works on most cases but fails on the following:
struct Bad {
std::vector<int> nums;
private:
int& operator[](size_t ind) {
return nums[ind];
}
};
static_assert(!Indexable<Bad>, "fail");
For some reason my concept ignores the fact that operator[] is defined private and returns true. What am I missing?
Typescript support four types of access modifiers: public, private, protected and read-only.
In TypeScript there are two ways to do this. The first option is to cast the object to any . The problem with this option is that you loose type safety and intellisense autocompletion. The second option is the intentional escape hatch.
The private modifier specifies that the member can only be accessed in its own class. The protected modifier specifies that the member can only be accessed within its own package (as with package-private) and, in addition, by a subclass of its class in another package.
TypeScript has two access modifiers – public and private. By default the members are public but you can explicitly add a public or private modifier to them.
This is GCC bug #67225 "Expression constraint with a constrained result turns off access checking", which will be fixed in GCC10.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With