mirror of
https://github.com/dlang/phobos.git
synced 2025-05-08 03:56:54 +03:00
Update Unique docs
This commit is contained in:
parent
1b85a4a1b1
commit
172f20e6bf
1 changed files with 4 additions and 8 deletions
|
@ -54,8 +54,6 @@ deleted at the end of the scope, unless it is transferred. The
|
||||||
transfer can be explicit, by calling $(D release), or implicit, when
|
transfer can be explicit, by calling $(D release), or implicit, when
|
||||||
returning Unique from a function. The resource can be a polymorphic
|
returning Unique from a function. The resource can be a polymorphic
|
||||||
class object, in which case Unique behaves polymorphically too.
|
class object, in which case Unique behaves polymorphically too.
|
||||||
|
|
||||||
Example:
|
|
||||||
*/
|
*/
|
||||||
struct Unique(T)
|
struct Unique(T)
|
||||||
{
|
{
|
||||||
|
@ -80,7 +78,7 @@ public:
|
||||||
/**
|
/**
|
||||||
Constructor that takes an rvalue.
|
Constructor that takes an rvalue.
|
||||||
It will ensure uniqueness, as long as the rvalue
|
It will ensure uniqueness, as long as the rvalue
|
||||||
isn't just a view on an lvalue (e.g., a cast)
|
isn't just a view on an lvalue (e.g., a cast).
|
||||||
Typical usage:
|
Typical usage:
|
||||||
----
|
----
|
||||||
Unique!(Foo) f = new Foo;
|
Unique!(Foo) f = new Foo;
|
||||||
|
@ -139,7 +137,7 @@ public:
|
||||||
{
|
{
|
||||||
return _p is null;
|
return _p is null;
|
||||||
}
|
}
|
||||||
/** Returns a unique rvalue. Nullifies the current contents */
|
/** Returns a unique rvalue. Nullifies the current contents. */
|
||||||
Unique release()
|
Unique release()
|
||||||
{
|
{
|
||||||
debug(Unique) writeln("Release");
|
debug(Unique) writeln("Release");
|
||||||
|
@ -148,11 +146,11 @@ public:
|
||||||
debug(Unique) writeln("return from Release");
|
debug(Unique) writeln("return from Release");
|
||||||
return u;
|
return u;
|
||||||
}
|
}
|
||||||
/** Forwards member access to contents */
|
/** Forwards member access to contents. */
|
||||||
RefT opDot() { return _p; }
|
RefT opDot() { return _p; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Postblit operator is undefined to prevent the cloning of $(D Unique) objects
|
Postblit operator is undefined to prevent the cloning of $(D Unique) objects.
|
||||||
*/
|
*/
|
||||||
@disable this(this);
|
@disable this(this);
|
||||||
|
|
||||||
|
@ -172,7 +170,6 @@ unittest
|
||||||
UBar g(UBar u)
|
UBar g(UBar u)
|
||||||
{
|
{
|
||||||
debug(Unique) writeln("inside g");
|
debug(Unique) writeln("inside g");
|
||||||
//return u;
|
|
||||||
return u.release;
|
return u.release;
|
||||||
}
|
}
|
||||||
auto ub = UBar(new Bar);
|
auto ub = UBar(new Bar);
|
||||||
|
@ -199,7 +196,6 @@ unittest
|
||||||
UFoo f(UFoo u)
|
UFoo f(UFoo u)
|
||||||
{
|
{
|
||||||
debug(Unique) writeln("inside f");
|
debug(Unique) writeln("inside f");
|
||||||
//return u;
|
|
||||||
return u.release;
|
return u.release;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue