mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2024-03-22 13:30:58 +08:00
T.61 example fixes (#1813)
This commit is contained in:
parent
fa726d5b0a
commit
5bbf843942
|
@ -18034,14 +18034,14 @@ This limits use and typically increases code size.
|
||||||
|
|
||||||
##### Example, bad
|
##### Example, bad
|
||||||
|
|
||||||
template<typename T, typename A = std::allocator{}>
|
template<typename T, typename A = std::allocator<T>>
|
||||||
// requires Regular<T> && Allocator<A>
|
// requires Regular<T> && Allocator<A>
|
||||||
class List {
|
class List {
|
||||||
public:
|
public:
|
||||||
struct Link { // does not depend on A
|
struct Link { // does not depend on A
|
||||||
T elem;
|
T elem;
|
||||||
T* pre;
|
Link* pre;
|
||||||
T* suc;
|
Link* suc;
|
||||||
};
|
};
|
||||||
|
|
||||||
using iterator = Link*;
|
using iterator = Link*;
|
||||||
|
@ -18062,11 +18062,11 @@ Typically, the solution is to make what would have been a nested class non-local
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct Link {
|
struct Link {
|
||||||
T elem;
|
T elem;
|
||||||
T* pre;
|
Link* pre;
|
||||||
T* suc;
|
Link* suc;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T, typename A = std::allocator{}>
|
template<typename T, typename A = std::allocator<T>>
|
||||||
// requires Regular<T> && Allocator<A>
|
// requires Regular<T> && Allocator<A>
|
||||||
class List2 {
|
class List2 {
|
||||||
public:
|
public:
|
||||||
|
@ -18076,11 +18076,11 @@ Typically, the solution is to make what would have been a nested class non-local
|
||||||
|
|
||||||
// ...
|
// ...
|
||||||
private:
|
private:
|
||||||
Link* head;
|
Link<T>* head;
|
||||||
};
|
};
|
||||||
|
|
||||||
List<int> lst1;
|
List2<int> lst1;
|
||||||
List<int, My_allocator> lst2;
|
List2<int, My_allocator> lst2;
|
||||||
|
|
||||||
Some people found the idea that the `Link` no longer was hidden inside the list scary, so we named the technique
|
Some people found the idea that the `Link` no longer was hidden inside the list scary, so we named the technique
|
||||||
[SCARY](http://www.open-std.org/jtc1/sc22/WG21/docs/papers/2009/n2911.pdf). From that academic paper:
|
[SCARY](http://www.open-std.org/jtc1/sc22/WG21/docs/papers/2009/n2911.pdf). From that academic paper:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user