Head Const

sclytrack via Digitalmars-d digitalmars-d at puremagic.com
Wed Feb 17 07:35:07 PST 2016


On Wednesday, 17 February 2016 at 12:46:08 UTC, Jonathan M Davis 
wrote:
> but violate the type system by casting away const and mutating, 
> not realizing that unlike C++, it's undefined behavior in D.
>
> Regardless of whether Walter's (and thus D's) stance on const 
> is the right one, it clearly doesn't jive with what a lot of 
> folks (particularly those from C++) are looking for or 
> expecting.
>
> - Jonathan M Davis

	struct (bla1, bla2) Test
	{
		int rc;
		bla1 int number;
		(bla2) Payload payload;

		void doSomething() (shared, immutable)
		{
		}
	}
	
	(shared, immutable) Test obj;

	bla1 becomes shared and bla2 becomes immutable, but
	the payload might not be immutable because it is
	(bla2) instead of just bla2.
	---
	Can it be made in a way that the blablas do not
	participate in the static if?
	----
	Could "shared", "immutable" be separated from
	the type int, float?
	
	(shared, immutable) Test!(int, float) obj;
	---
	I did some "const(immutable) int" and the the
	compiler says basic type expected.

	What is the basic type from "const(shared, immutable)",
	would that be "const(shared const, const)"?

	And then the basic type from "const(const, immutable)"
	would be "const".
	---
	Also would it be possible to determine the implicit
	conversion rules based solely on these qualifiers and
	not on the content of the object?
	
	(const, const) Test t = new (const, immutable) Test();
	const Test t = new (const,const) Test();
	---


More information about the Digitalmars-d mailing list