diff --git a/ctl/unique_ptr.cc b/ctl/unique_ptr.cc new file mode 100644 index 000000000..daeda3b1b --- /dev/null +++ b/ctl/unique_ptr.cc @@ -0,0 +1,19 @@ +// -*- mode:c++; indent-tabs-mode:nil; c-basic-offset:4; coding:utf-8 -*- +// vi: set et ft=cpp ts=4 sts=4 sw=4 fenc=utf-8 :vi +// +// Copyright 2024 Justine Alexandra Roberts Tunney +// +// Permission to use, copy, modify, and/or distribute this software for +// any purpose with or without fee is hereby granted, provided that the +// above copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL +// WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE +// AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL +// DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR +// PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#include "unique_ptr.h" diff --git a/ctl/unique_ptr.h b/ctl/unique_ptr.h new file mode 100644 index 000000000..067196e94 --- /dev/null +++ b/ctl/unique_ptr.h @@ -0,0 +1,31 @@ +// -*-mode:c++;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8-*- +// vi: set et ft=cpp ts=4 sts=4 sw=4 fenc=utf-8 :vi +#ifndef COSMOPOLITAN_CTL_UNIQUE_PTR_H_ +#define COSMOPOLITAN_CTL_UNIQUE_PTR_H_ +#include <__utility/forward.h> +#include <__utility/move.h> +#include <__utility/swap.h> + +namespace ctl { + +template +using default_delete = decltype([](T* p) { + delete p; +}); + +template> +struct unique_ptr +{ + T* p = 0; + + using pointer = T*; + using element_type = T; + using deleter_type = D; + + constexpr unique_ptr(nullptr_t = nullptr) { } + explicit unique_ptr(pointer p) : p(p) { } + +}; + +} // namespace ctl +#endif // COSMOPOLITAN_CTL_UNIQUE_PTR_H_