Commit graph

356 commits

Author SHA1 Message Date
Matt Kline
d24b738ccc Clean up Unique alias this 2015-04-17 00:32:05 -07:00
Matt Kline
836c55197e Do not let Unique escape underlying references
See https://github.com/D-Programming-Language/phobos/pull/3139#discussion-diff-28203345
2015-04-17 00:24:22 -07:00
Matt Kline
e112ec9b7f Return Unique to malloc/free
Marking its various bits as @nogc is still proving to be a challenge
since Object.destroy is not @nogc, among other things.

We _are_ using GC.addRange and GC.removeRange to handle anything
inside the underlying type that uses GC.
Why the user would do this in conjunction with Unique is
questionable, but until we can explicitly forbid doing so, let's
not break garbage collection for them.

Note that this also makes nested structs and classes impossible,
because there is no way AFAIK to get the frame pointer into
unique()
2015-04-16 23:58:28 -07:00
Matt Kline
c5605bf2c8 Turn Unique.create into a freestanding unique()
Also cleaned up the Unique documentation a bit.
Unfortunately some of the unittests could not be used as documented
unittests because placing them in the struct gives an error about
RTInfo!(Nested) being recursvely expanded.
2015-04-13 00:04:00 -07:00
Matt Kline
dba6bd5464 Revamp and cleanup of Unique
From the related pull request
(https://github.com/D-Programming-Language/phobos/pull/3139),
there seems to be a general consensus that it is more important to
do Unique "right", even if that means breaking changes, so long as
there is a clean migration path. With that in mind, I have made the
following additional changes:

- Instead of constructors that take a RefT, Uniques can now be
  created one of two ways: via .create or .fromNested.
  See the DDocs of both for details.

- opDot is replaced with "alias _p this". A cursorty Google search
  indicates that opDot is deprecated and that alias this is the
  preferred method. Like C++'s unique_ptr, Unique now enjoys
  pointer-like operations (such as dereferencing),
  but cannot be set to null or assigned from a different pointer
  due to opAssign and the disabled postblit constructor.

- Consequently, isEmpty has been removed. Instead, just use
  is null as you would with a pointer.

- Removal of redundant unit tests

- Various comment and unit test cleanup
2015-04-06 23:25:23 -07:00
Matt Kline
b3c94c26d1 Make Unique use the GC again
It is currently impossible (or so it seems) to use malloc and
emplace to create a nested class or struct, so we'll return to
using the GC for now. We'll also restore the constructors that take
a RefT, as using new _inside_ the context of the nested class or
struct is apparently the only way to create one currently.
2015-04-05 15:44:02 -07:00
Matt Kline
6d42be9fdd Use class version of std.conv.emplace for Unique
I picked up the trick of converting a pointer into an array
using the [0 .. size] syntax from std/regex/package.d.

Unique.create is still segfaulting, but this seems to be an issue
with the class version of emplace regardless of this Unique work.
The bug can be found here:
https://issues.dlang.org/show_bug.cgi?id=14402
2015-04-03 01:29:23 -07:00
Matt Kline
a5150a043b Fix outOfMemoryError import 2015-04-03 00:57:12 -07:00
Matt Kline
db544d55d5 Issue onOutOfMemoryError on bad malloc in Unique 2015-04-03 00:45:23 -07:00
Matt Kline
f6994ea02f Improve std.typecons.Unique
Whenever D is brought up to the general programming public,
the garbage collector is quickly raised as a point of contention.
Regardless of how legitimate or well-informed these concerns are,
it would be a massive public relations boon --- and great for the language,
to boot --- if we could trot out a solid said of RAII-based smart pointers
for those who prefer to use them. We have a solid start in
std.typecons.Unique and std.typecons.RefCounted.
Unfortunately, these classes seem to be victims of bit rot and
compiler bugs of days long gone.

An overview of the changes in this commit is as follows:

- Unique's underlying data now uses malloc and free
  instead of the garbage collector. Given that many people use RAII
  smart pointers to escape the GC, it seems to make more sense to
  avoid it here. On a related note, isn't delete deprecated?
  The current destructor uses it.

- std.algorithm.move is used instead of a special release
  member function. Whether by design or by happy accident,
  move transfers ownership between Unique pointers in a very
  similar manner to C++'s std::move with std::unique_ptr.
  Along with being a familiar paradigm to C++ users,
  using move to transfer ownership makes more intuitive sense
  and builds consistency with the rest of Phobos.

- With std.algorithm.move transferring ownership, release now just
  frees the underlying pointer and nulls the Unique.

- Unique.create is no longer compiled out using version(None).
  Regardless of whether or not there is language support for
  checking uniqueness, a utility function that creates a Unique,
  taking the same arguments as the underlying type's constructor,
  is extremely useful, as demonstrated by the addition of
  make_unique to C++14.

- Because Unique.create is now in place and Unique is backed with
  malloc, constructors taking a pointer have been removed.
  This encourages the use of create as the idiomatic,
  consistent method to, well, create Unique objects.
  If one can only get a Unique by calling create or moving another
  into it, we also ensures uniqueness in one fell swoop.

- A new method, get, returns the underlying pointer, for use in
  functions and code that do not play a role in the life cycle
  of the object. Smart pointers are as much about ownership
  semantics as they are about allocating and freeing memory,
  and non-owning code should continue to refer to data using a raw
  pointer or a reference.
2015-04-02 01:17:40 -07:00
H. S. Teoh
20e62954d3 Merge pull request #3100 from MetaLang/proxy-doc-fixes
Improve documentation for std.typecons.Proxy
2015-03-27 10:09:43 -07:00
Robert Schadek
9e4dcb0a01 Merge pull request #3101 from MetaLang/tuple-doc-more-fixes
Further improvements for Tuple's documentation
2015-03-26 21:17:28 +01:00
MetaLang
749cc5ca51 Further improvements for Tuple's documentation 2015-03-26 15:54:05 -03:00
H. S. Teoh
bcf0fcecac Merge pull request #3102 from MetaLang/rebindable-add-params
Improve Rebindable documentation
2015-03-25 17:29:19 -07:00
H. S. Teoh
ccccf0f8cf Merge pull request #3104 from MetaLang/alignforsize-doc-fixes
Improve alignForSize Documentation
2015-03-25 16:30:36 -07:00
MetaLang
71a074d5cb Add Params section to UnqualRef documentation 2015-03-24 21:18:05 -03:00
MetaLang
c67867360d Improve documentation for std.typecons.Proxy 2015-03-24 21:06:42 -03:00
MetaLang
a75afe241d Improve alignForSize Documentation 2015-03-24 06:49:02 -03:00
MetaLang
65921b7739 Improve Rebindable documentation 2015-03-24 06:36:34 -03:00
MetaLang
82797e7a15 Improved std.typecons.Tuple documentation.
- Fix various typos
	- Add examples
    - Move old examples to documented unit tests
	- Document certain behaviours (such as how tuples are compared)
2015-03-20 19:08:44 -03:00
k-hara
6a8345bbc6 fix Issue 14213 - Strange deprecated message in std.typecons.Proxy with using method 2015-03-07 11:20:25 +09:00
H. S. Teoh
32ca6fb720 forward() has moved to std.functional. 2015-02-16 12:12:45 -08:00
Jakob Ovrum
96f682aba2 Reject instantiating RefCounted with interface types 2015-02-11 12:46:35 +09:00
Martin Nowak
06fd47ffec fix Issue 14106 - sort is unsafe in debug mode
- need attribute inference to toString delegate
2015-02-02 22:39:13 +01:00
Andrei Alexandrescu
71e3ecf680 Merge pull request #2934 from WalterBright/dip25
DIP25: make phobos work with it
2015-01-30 13:59:37 -08:00
Walter Bright
dc302d26a4 DIP25: make phobos work with it 2015-01-30 12:02:48 -08:00
Robert burner Schadek
5f633b7e82 typecons documentation update
* moved examples into unittests
2015-01-29 22:38:59 +01:00
Peter Alexander
052c50d3cb Fix Issue 13781 - Tuple assign should be @nogc 2014-12-31 19:23:35 +00:00
ZombineDev
1e803e65f6 Fix typo in BitFlags unit test. 2014-12-18 16:39:18 +02:00
Peter Alexander
d1ffb938b5 Fix Issue 10104 - Group of array of const/immutable 2014-12-15 20:22:07 +00:00
H. S. Teoh
ecd25fdd26 Merge pull request #2058 from lultimouomo/flags
Add Flags template
2014-12-13 13:05:39 -08:00
Luca Niccoli
ec9965d656 Add BitFlags template
BitFlags is a typecons template for storing OR combinaton of enum
values in a type safe fashion.
2014-12-10 10:13:26 +01:00
Peter Alexander
3d8838060f Issue 13837 - Allow names for tuple 2014-12-09 22:42:39 +00:00
Igor Stepanov
74e8a95c2c allow casting Typedef to another Typedef 2014-12-02 19:01:19 +03:00
Hara Kenji
06ac5031b1 Merge pull request #2740 from garlic-flavor/master
std.typecons.Proxy inside classes
2014-11-25 00:01:08 +09:00
garlic-flavor
e5269c8533 specialization of std.typecons.Proxy for classes
using selective import

remove nonsense code

integration of static this.

add a comment

avoiding some warnings

remove InvalidTypeException

improve readability
2014-11-24 03:26:08 +09:00
Ilya Yaroshenko
2c744b54e1 std.range: constraints => primitives
See discussion and voting in #2661
2014-11-23 20:05:20 +03:00
k-hara
8248c6b1e8 fix property enforcement 2014-11-22 01:50:41 +09:00
David Nadlinger
7e80e67630 Merge pull request #2728 from 9il/typecons
std.typecons: remake toString to template, clean module imports
2014-11-20 22:11:54 +01:00
Ilya Yaroshenko
af02101ab9 std.typecons: remake toString to template, clean module imports
update datetime unittests
2014-11-20 23:08:33 +03:00
Lars T. Kyllingstad
96583fe46b isNaN() is not a property
...so it shouldn't be used as one.
2014-11-20 20:22:00 +01:00
k-hara
b80083f198 fix property enforcement 2014-11-20 22:37:57 +09:00
H. S. Teoh
512b0ab382 Document new idiom for using Flag. 2014-11-19 07:59:54 -08:00
Ilya Yaroshenko
efb880f651 move format to std.format
The reason is to do not import `std.uni` tables, `std.string` and
probably `std.algorithm`. Note that format is used in CTFE code and
`Exception` handing.

 And it is more comfortable to import `format` from `std.format`.

std.format: clean imports (2)

remove import std.math : pow from std.uni

update scope imports in std.algorithm

update scope imports in std.exception

doFormat -> template

update scope imports in std.typecons

update scope imports in std.functional

update scope imports in std.range

update std.conv scope import

std.format: clean imports (2)

remove import std.math : pow from std.uni

update scope imports in std.algorithm

update scope imports in std.exception

doFormat -> template

update scope imports in std.typecons

update scope imports in std.functional

update scope imports in std.range

move sfromat

add public import of sformat

use std.uni
2014-11-18 22:14:28 +03:00
garlic-flavor
31f39c0158 a bug was removed. 2014-11-16 00:40:10 +09:00
garlic-flavor
67571fccde Merge https://github.com/D-Programming-Language/phobos 2014-11-15 23:44:49 +09:00
Geod24
10d59acfed Remove private staticFilter from AutoImplement and use std.typetuple.Filter instead 2014-11-09 21:47:15 +01:00
garlic-flavor
7cd3f18573 some update 2014-11-04 03:38:47 +09:00
Dmitry Olshansky
2e58214d1d Merge pull request #2587 from MetaLang/nullable-tostring
Fix Issue 10915 - std.typecons.Nullable throws in writeln() if it's null
2014-10-31 22:03:05 +03:00
MetaLang
2c8fdeb0b0 Fix Issue 10915 - std.typecons.Nullable throws in writeln() if it's null 2014-10-11 21:06:15 -03:00