Skip to content

Commit

Permalink
add intrusive_ptr.d
Browse files Browse the repository at this point in the history
  • Loading branch information
vitamin committed Jul 29, 2021
1 parent 126e8d5 commit d70dd80
Show file tree
Hide file tree
Showing 3 changed files with 322 additions and 0 deletions.
98 changes: 98 additions & 0 deletions docs/autoptr/common/SharedControlType.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>Alias SharedControlType</title>
<link rel="stylesheet" type="text/css" href="../../styles/ddox.css"/>
<link rel="stylesheet" href="../../prettify/prettify.css" type="text/css"/>
<script type="text/javascript" src="../../scripts/jquery.js">/**/</script><script type="text/javascript" src="../../scripts/ddox.js">/**/</script>
</head>
<body onload="setupDdox();">
<nav id="main-nav">
<noscript>
<p style="color: red">The search functionality needs JavaScript enabled</p>
</noscript>
<div id="symbolSearchPane" style="display: none">
<form action="#" method="GET">
<input id="symbolSearch" type="text" name="q" placeholder="Search for symbols" autocomplete="off" onchange="performSymbolSearch(40);" onkeypress="this.onchange();" onpaste="this.onchange();" oninput="this.onchange();"/>
</form>
<ul id="symbolSearchResults" class="symbolList" style="display: none"></ul><script type="application/javascript" src="../../symbols.js"></script><script type="application/javascript">var symbolSearchRootDir = "../../";
$('#symbolSearchPane').show();</script>
</div>
<ul class="tree-view">
<li class="tree-view ">
<div class="package ">autoptr
</div>
<ul class="tree-view">
<li>
<div class="module selected">
<a href="../../autoptr/common.html">common</a>
</div>
</li>
<li>
<div class="module ">
<a href="../../autoptr/intrusive_ptr.html">intrusive_ptr</a>
</div>
</li>
<li>
<div class="module ">
<a href="../../autoptr/rc_ptr.html">rc_ptr</a>
</div>
</li>
<li>
<div class="module ">
<a href="../../autoptr/shared_ptr.html">shared_ptr</a>
</div>
</li>
<li>
<div class="module ">
<a href="../../autoptr/unique_ptr.html">unique_ptr</a>
</div>
</li>
</ul>
</li>
</ul>
</nav>
<div id="main-contents">
<h1>Alias SharedControlType</h1><p>Default <code class="lang-d"><a href="../../autoptr/common/ControlBlock.html"><span class="typ">ControlBlock</span></a></code> for <code class="lang-d"><span class="typ">SharedPtr</span></code> and <code class="lang-d"><span class="typ">RcPtr</span></code>.
</p>
<div class="prototype">
<code class="lang-d">
<div class="single-prototype">
<span class="kwd">alias</span> <span class="pln">SharedControlType</span>
<span class="pun">=</span> <a href="../../autoptr/common/ControlBlock.html"><span class="typ">ControlBlock</span></a>!(int,int)<span class="pun">;</span>
</div>
</code>
</div>


<footer>
<table class="license-info">
<tr>
<th>Authors</th>
<td>
<p>github.com/submada/basic_string, Adam Búš
</p>

</td>
</tr>
<tr>
<th>Copyright</th>
<td>

</td>
</tr>
<tr>
<th>License</th>
<td>
<p>www.boost.org/LICENSE_1_0.txt, Boost License 1.0.
</p>

</td>
</tr>
</table>
<p class="faint">Generated using the DDOX documentation generator</p>
</footer>
</div>
</body>
</html>
98 changes: 98 additions & 0 deletions docs/autoptr/common/UniqueControlType.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>Alias UniqueControlType</title>
<link rel="stylesheet" type="text/css" href="../../styles/ddox.css"/>
<link rel="stylesheet" href="../../prettify/prettify.css" type="text/css"/>
<script type="text/javascript" src="../../scripts/jquery.js">/**/</script><script type="text/javascript" src="../../scripts/ddox.js">/**/</script>
</head>
<body onload="setupDdox();">
<nav id="main-nav">
<noscript>
<p style="color: red">The search functionality needs JavaScript enabled</p>
</noscript>
<div id="symbolSearchPane" style="display: none">
<form action="#" method="GET">
<input id="symbolSearch" type="text" name="q" placeholder="Search for symbols" autocomplete="off" onchange="performSymbolSearch(40);" onkeypress="this.onchange();" onpaste="this.onchange();" oninput="this.onchange();"/>
</form>
<ul id="symbolSearchResults" class="symbolList" style="display: none"></ul><script type="application/javascript" src="../../symbols.js"></script><script type="application/javascript">var symbolSearchRootDir = "../../";
$('#symbolSearchPane').show();</script>
</div>
<ul class="tree-view">
<li class="tree-view ">
<div class="package ">autoptr
</div>
<ul class="tree-view">
<li>
<div class="module selected">
<a href="../../autoptr/common.html">common</a>
</div>
</li>
<li>
<div class="module ">
<a href="../../autoptr/intrusive_ptr.html">intrusive_ptr</a>
</div>
</li>
<li>
<div class="module ">
<a href="../../autoptr/rc_ptr.html">rc_ptr</a>
</div>
</li>
<li>
<div class="module ">
<a href="../../autoptr/shared_ptr.html">shared_ptr</a>
</div>
</li>
<li>
<div class="module ">
<a href="../../autoptr/unique_ptr.html">unique_ptr</a>
</div>
</li>
</ul>
</li>
</ul>
</nav>
<div id="main-contents">
<h1>Alias UniqueControlType</h1><p>Default <code class="lang-d"><a href="../../autoptr/common/ControlBlock.html"><span class="typ">ControlBlock</span></a></code> for <code class="lang-d"><span class="typ">UniquePtr</span></code>.
</p>
<div class="prototype">
<code class="lang-d">
<div class="single-prototype">
<span class="kwd">alias</span> <span class="pln">UniqueControlType</span>
<span class="pun">=</span> <a href="../../autoptr/common/ControlBlock.html"><span class="typ">ControlBlock</span></a>!(void,void)<span class="pun">;</span>
</div>
</code>
</div>


<footer>
<table class="license-info">
<tr>
<th>Authors</th>
<td>
<p>github.com/submada/basic_string, Adam Búš
</p>

</td>
</tr>
<tr>
<th>Copyright</th>
<td>

</td>
</tr>
<tr>
<th>License</th>
<td>
<p>www.boost.org/LICENSE_1_0.txt, Boost License 1.0.
</p>

</td>
</tr>
</table>
<p class="faint">Generated using the DDOX documentation generator</p>
</footer>
</div>
</body>
</html>
126 changes: 126 additions & 0 deletions src/autoptr/internal/traits.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
module autoptr.internal.traits;



import std.traits : isFunctionPointer, isDelegate;

public auto assumeNoGC(T)(T t)@trusted
in(isFunctionPointer!T || isDelegate!T){
import std.traits : functionAttributes, FunctionAttribute, SetFunctionAttributes, functionLinkage;

enum attrs = functionAttributes!T | FunctionAttribute.nogc;
return cast(SetFunctionAttributes!(T, functionLinkage!T, attrs)) t;
}

public auto assumePure(T)(T t)@trusted
in(isFunctionPointer!T || isDelegate!T){
import std.traits : functionAttributes, FunctionAttribute, SetFunctionAttributes, functionLinkage;

enum attrs = functionAttributes!T | FunctionAttribute.pure_;
return cast(SetFunctionAttributes!(T, functionLinkage!T, attrs)) t;
}

public auto assumePureNoGc(T)(T t)@trusted
in(isFunctionPointer!T || isDelegate!T){
import std.traits : functionAttributes, FunctionAttribute, SetFunctionAttributes, functionLinkage;

enum attrs = functionAttributes!T | FunctionAttribute.pure_ | FunctionAttribute.nogc;
return cast(SetFunctionAttributes!(T, functionLinkage!T, attrs)) t;
}

public auto assumePureNoGcNothrow(T)(T t)@trusted
in(isFunctionPointer!T || isDelegate!T){
import std.traits : functionAttributes, FunctionAttribute, SetFunctionAttributes, functionLinkage;

enum attrs = functionAttributes!T | FunctionAttribute.pure_ | FunctionAttribute.nogc | FunctionAttribute.nothrow_;
return cast(SetFunctionAttributes!(T, functionLinkage!T, attrs)) t;
}


//Same as `std.traits.hasIndirections` but for classes.
public template classHasIndirections(T){
import std.traits : hasIndirections;

static if(is(T == class)){
enum bool classHasIndirections = (){

import std.traits : BaseClassesTuple;
import std.meta : AliasSeq;

bool has_indirection = false;

static foreach (alias B; AliasSeq!(T, BaseClassesTuple!T)) {
static foreach(alias Var; typeof(B.init.tupleof)){
static if(hasIndirections!Var){
has_indirection = true;
//has_indirection = true;
//break TOP;
}
}
}

return has_indirection;
}();
}
else{
enum bool classHasIndirections = false;
}
}

//alias to `T` if `T` is class or interface, otherwise `T*`.
public template PtrOrRef(T){
static if(is(T == class) || is(T == interface))
alias PtrOrRef = T;
else
alias PtrOrRef = T*;
}

public enum bool isReferenceType(T) = is(T == class) || is(T == interface);



public template ElementReferenceTypeImpl(Type){
import std.traits : Select, isDynamicArray;
import std.range : ElementEncodingType;

static if(isDynamicArray!Type)
alias ElementReferenceTypeImpl = ElementEncodingType!Type[];
else
alias ElementReferenceTypeImpl = PtrOrRef!Type;

}

//alias to `AliasSeq` containing `T` if `T` has state, otherwise a empty tuple.
public template AllocatorWithState(T){
import std.experimental.allocator.common : stateSize;
import std.meta : AliasSeq;

enum bool hasStatelessAllocator = (stateSize!T == 0);

static if(stateSize!T == 0)
alias AllocatorWithState = AliasSeq!();
else
alias AllocatorWithState = AliasSeq!T;
}

//alias to stateless allocator instance
public template statelessAllcoator(T){
import std.experimental.allocator.common : stateSize;
import std.traits : hasStaticMember;

static assert(stateSize!T == 0);

static if(hasStaticMember!(T, "instance"))
alias statelessAllcoator = T.instance;
else
enum T statelessAllcoator = T.init;
}

//Size of instance, if `T` is class then `__traits(classInstanceSize, T)`, otherwise `T.sizeof`
public template instanceSize(T){
static if(is(T == class))
enum size_t instanceSize = __traits(classInstanceSize, T);
else
enum size_t instanceSize = T.sizeof;

}

0 comments on commit d70dd80

Please sign in to comment.