Jump to: TypeClass Bool Integer Float Complex Imaginary Class Pointer Array Other Box unboxable type data toString opEquals opCmp toHash box boxArray boxArrayToArguments UnboxException object outputType unboxCastReal unboxCastInteger unboxCastComplex unboxCastImaginary unbox
This module is a set of types and functions for converting any object (value or heap) into a generic box type, allowing the user to pass that object around without knowing what's in the box, and then allowing him to recover the value afterwards.
WARNING:
This module is being phased out. You may want to use std.variant for new code.
Example:
// Convert the integer 45 into a box.
Box b = box(45);
// Recover the integer and cast it to real.
real r = unbox!(real)(b);
That is the basic interface and will usually be all that you need to understand. If it cannot unbox the object to the given type, it throws UnboxException. As demonstrated, it uses implicit casts to behave in the exact same way that static types behave. So for example, you can unbox from int to real, but you cannot unbox from real to int: that would require an explicit cast.
This therefore means that attempting to unbox an int as a string will throw an error instead of formatting it. In general, you can call the toString method on the box and receive a good result, depending upon whether std.string.format accepts it.
Boxes can be compared to one another and they can be used as keys for associative arrays.
There are also functions for converting to and from arrays of boxes.
Example:
// Convert arguments into an array of boxes.
Box[] a = boxArray(1, 45.4, "foobar");
// Convert an array of boxes back into arguments.
TypeInfo[] arg_types;
void* arg_data;
boxArrayToArguments(a, arg_types, arg_data);
// Convert the arguments back into boxes using a
// different form of the function.
a = boxArray(arg_types, arg_data);
One use of this is to support a variadic function more easily and robustly; simply call "boxArray(arguments, argptr)", then do whatever you need to do with the array.
Authors:
Burton Radons
License:
Public Domain
enum TypeClass;
The type class returned from Box.findTypeClass; the order of entries is important.
Bool
< bool
Integer
< byte, ubyte, short, ushort, int, uint, long, ulong
Float
< float, double, real
Complex
< cfloat, cdouble, creal
Imaginary
< ifloat, idouble, ireal
Class
< Inherits from Object
Pointer
< Pointer type (T *)
Array
< Array type (T [])
Other
< Any other type, such as delegates, function pointers, struct, void...
struct Box;
Box is a generic container for objects (both value and heap), allowing the user to box them in a generic form and recover them later. A box object contains a value in a generic fashion, allowing it to be passed from one place to another without having to know its type. It is created by calling the box function, and you can recover the value by instantiating the unbox template.
bool unboxable(TypeInfo test);
Return whether this value could be unboxed as the given type without throwing.
const TypeInfo type();
Property for the type contained by the box. This is initially null and cannot be assigned directly.
Returns:
the type of the contained object.
const const(void)[] data();
Property for the data pointer to the value of the box. This is initially null and cannot be assigned directly.
Returns:
the data array.
string toString();
Attempt to convert the boxed value into a string using std.string.format; this will throw if that function cannot handle it. If the box is uninitialized then this returns "".
bool opEquals(Box other);
Compare this box's value with another box. This implicitly casts if the types are different, identical to the regular type system.
float opCmp(Box other);
Compare this box's value with another box. This implicitly casts if the types are different, identical to the regular type system.
hash_t toHash();
Return the value's hash.
Box box(...);
Box the single argument passed to the function. If more or fewer than one argument is passed, this will assert.
Box box(TypeInfo type, void* data);
Box the explicitly-defined object. type must not be null; data must not be null if the type's size is greater than zero. The data is copied.
Box[] boxArray(TypeInfo[] types, void* data);
Convert a list of arguments into a list of boxes.
Box[] boxArray(...);
Box each argument passed to the function, returning an array of boxes.
void boxArrayToArguments(Box[] arguments, out TypeInfo[] types, out void* data);
Convert an array of boxes into an array of arguments.
class UnboxException: object.Exception;
This class is thrown if unbox is unable to cast the value into the desired result.
Box object;
This is the box that the user attempted to unbox.
TypeInfo outputType;
This is the type that the user attempted to unbox the value as.
this(Box object, TypeInfo outputType);
Assign parameters and create the message in the form "Could not unbox from type ... to ... ."
T unboxCastReal(T)(Box value);
A generic unboxer for the real numeric types.
T unboxCastInteger(T)(Box value);
A generic unboxer for the integral numeric types.
T unboxCastComplex(T)(Box value);
A generic unboxer for the complex numeric types.
T unboxCastImaginary(T)(Box value);
A generic unboxer for the imaginary numeric types.
T unbox(T)(Box value);
The unbox template takes a type parameter and returns a function that takes a box object and returns the specified type.
To use it, instantiate the template with the desired result type, and then call the function with the box to convert. This will implicitly cast base types as necessary and in a way consistent with static types - for example, it will cast a boxed byte into int, but it won't cast a boxed float into short.
Throws:
UnboxException if it cannot cast
Example:
Box b = box(4.5);
bit u = unboxable!(real)(b); // This is true.
real r = unbox!(real)(b);
Box y = box(4);
int x = unbox!(int) (y);
bool unboxable(T)(Box value);
Return whether the value can be unboxed as the given type; if this returns false, attempting to do so will throw UnboxException.
分享到:
相关推荐
(自适应移动端)响应式大气的教育培训机构网站源码 教育培训集团网站pbootcms模板 安装教程https://www.a5ymg.cn/480.html
开源项目-sermodigital-boxer.zip,boxer - streaming encryption and decryption per an AGL article
Boxer Text Editor 强力文本编辑器.rar
templatemo_446_boxer.zip
Boxer text editor 老朽痴拙汉化版(拳击手文本编辑器) 拳击手是简单易用,足够强大完美的工具,甚至能编辑最复杂的文本任务,是窗口功能全面的文本编辑器。 用于编辑 HTML 文件、 程序源代码、 平构数据库文件、 二...
boxer 是一款简单的用户自定义模板,用来生成 JSON 对象模型表示。 标签:boxer
此存储库包含与src/data/boxer目录中的xdrs.dtd文件对应的类层次结构。 它允许将带注释的 XML Boxer 输出快速反序列化为 Java 对象。 先决条件是 maven(用于解析)和构建和运行的(用于输出)。 修改属性文件并...
sketch-bounding-boxer, 在草图文档中,切换'boundingBox'图层的可见性 :为什么草图绑定拳击手在我们的草图文档中,我们经常使用"boundingbox"层,例如。 icon 层组查看( 并使用)的实际尺寸和边界。 由于我们不想...
一个实用程序,可帮助您替换没有可见螺柱或带有盒子的管的LDraw零件。 节省渲染时间和CPU功耗。
示例 vagrant-boxer 和 vagrant-catalog 设置这个存储库是如何设置一个服务器然后在多个 vagrant 项目中使用它的示例。 在一个项目中,我们创建了一个基本框,然后我们使用在 vagrant-catalog 服务器上发布它。 在另...
因此,这里的boxer(名称可能会更改),您可以使用它来快速运行node或npm命令,以执行诸如安装typscript编译器并按需运行该编译器以创建javascript资源之类的工作。 库是一个WIP,因此其功能不完整,不缺少任何...
阅读《BoxeR:Box-Attention for 2D and 3D Transformers》论文后,并参考了网络上的一些资料,做了一个论文分享ppt
有趣的拳击手狗和可爱的小狗,每个新选项卡的不同高清背景。 此附加组件是专门为所有爱狗人士设计的。 我们收集了可爱又有趣的拳击手和小狗的高清壁纸,每当您打开一个新标签页时,您都可以享受不同的背景。...
流浪拳击手 管理装箱 Vagrant VM 的应用程序,用作专用盒分发系统的基本盒。... 然后,您可以选择将 /usr/local/bin/boxer.php 之类的内容符号链接到此内容,以便只需键入boxer.php从您的路径运行 $ sudo ln -sf /pa
findById ( 356831 , function ( err , boxer ) { console . log ( boxer . name ) ; // 'Gennady Golovkin'} ) ;boxrec . findByName ( 'Carl Froch' , function ( err , boxer ) { console . log ( boxer . ...
将您的Ruby代码放在文件lib/boxer_scaffold 。 要试验该代码,请运行bin/console进行交互式提示。 待办事项:删除此内容和上面的文字,并描述您的宝石 安装 将此行添加到您的应用程序的Gemfile中: gem 'boxer_...
拳击手-人类氯化钠 这个Go包围绕NaCl包实现了一个方便包装。 它的主要目的是向用户隐藏对现时...go get github.com/xrstf/boxer 用法 dataToEncrypt := "I am something to keep secret." password := "sup3r s3cur3
您还将找到Deutscher Boxer,German Boxer品种和Boxer幼犬的高分辨率图像。 功能:•根据您的喜好自定义仪表板•待办事项列表可跟踪您的目标•每个新选项卡均具有惊人的图像•定期添加新的鼓舞人心的照片•使用Yahoo...
使用Boxer Property的Google Chrome扩展程序可以快速访问我们的网站页面,社交媒体和社交网络。 使用我们的扩展程序可以快速访问我们的办公空间租赁网站,我们的社交媒体内容以及我们的社交网络更新。 有关此扩展或...
With the possible exceptions of boxer Muhammad Ali and baseball player Babe Ruth, no athlete has made a greater impact on American society-or in the world-than Michael Jordan. Follow the life of one ...