Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requiring smart pointers to be initialized #4

Closed
Snaipe opened this issue Jan 21, 2015 · 1 comment
Closed

Requiring smart pointers to be initialized #4

Snaipe opened this issue Jan 21, 2015 · 1 comment

Comments

@Snaipe
Copy link
Owner

Snaipe commented Jan 21, 2015

In C++, unique_ptr and shared_ptr require a value, since they have ownership over it -- but in this case, since we don't wrap a pointer but return actual unintialized memory, I was wondering if the unique_ptr and shared_ptr macro should take a mandatory value and initialize the memory with it.

Usage would be:

smart int *some_int = unique_ptr(int, (1));
smart double *some_array = unique_ptr(double[4], ({1, 2.5, 3.2, 0.999}), some_dtor);
smart long *some_zero_padded_array = unique_ptr(long[25], ({1}), &some_meta, sizeof (some_meta));

struct { 
    int a;
    long b;
    double c;
} s;
smart struct s *some_struct = unique_ptr(struct s, ({ .a = 1, .b = 2 }), dtor, &some_meta, sizeof (some_meta));

Parenthesis over the value are unfortunate, but would be mandatory to allow struct and array literals to be passed, since curly braces are known to not group commas together in macro parameters.

I am still not sure about that to be honest since one could desire to initialize the memory in a more specific way, but to be fair, that's what smalloc should be for.

@Snaipe
Copy link
Owner Author

Snaipe commented Jan 26, 2015

This has been addressed in commit 333c650.

@Snaipe Snaipe closed this as completed Jan 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant