File tree Expand file tree Collapse file tree
examples/base/lifetime_tag Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #
2+ # .============.
3+ # // M A K E / \
4+ # // C++ DEV / \
5+ # // E A S Y / \/ \
6+ # ++ ----------. \/\ .
7+ # \\ \ \ /\ /
8+ # \\ \ \ /
9+ # \\ \ \ /
10+ # -============'
11+ #
12+ # Copyright (c) 2018 Hevake and contributors, all rights reserved.
13+ #
14+ # This file is part of cpp-tbox (https://github.com/cpp-main/cpp-tbox)
15+ # Use of this source code is governed by MIT license that can be found
16+ # in the LICENSE file in the root of the source tree. All contributing
17+ # project authors may be found in the CONTRIBUTORS.md file in the root
18+ # of the source tree.
19+ #
20+
21+ PROJECT := examples/base/lifetime_tag
22+ EXE_NAME := ${PROJECT}
23+
24+ CPP_SRC_FILES := main.cpp
25+
26+ CXXFLAGS := -DMODULE_ID='"$(EXE_NAME ) "' $(CXXFLAGS )
27+ LDFLAGS += -ltbox_base -ldl
28+
29+ include $(TOP_DIR ) /mk/exe_common.mk
Original file line number Diff line number Diff line change 1+ /*
2+ * .============.
3+ * // M A K E / \
4+ * // C++ DEV / \
5+ * // E A S Y / \/ \
6+ * ++ ----------. \/\ .
7+ * \\ \ \ /\ /
8+ * \\ \ \ /
9+ * \\ \ \ /
10+ * -============'
11+ *
12+ * Copyright (c) 2026 Hevake and contributors, all rights reserved.
13+ *
14+ * This file is part of cpp-tbox (https://github.com/cpp-main/cpp-tbox)
15+ * Use of this source code is governed by MIT license that can be found
16+ * in the LICENSE file in the root of the source tree. All contributing
17+ * project authors may be found in the CONTRIBUTORS.md file in the root
18+ * of the source tree.
19+ */
20+ #include < tbox/base/lifetime_tag.hpp>
21+ #include < iostream>
22+
23+ using namespace std ;
24+
25+ int main ()
26+ {
27+ struct Tmp {
28+ int value;
29+ tbox::LifetimeTag lifetime_tag;
30+ };
31+
32+ auto tmp = new Tmp{10 };
33+ auto watch = tmp->lifetime_tag .get ();
34+ auto print_func = [tmp, watch] (const char *prompt) {
35+ if (watch)
36+ cout << ' [' << prompt << " ] it's alive, value " << tmp->value << endl;
37+ else
38+ cout << ' [' << prompt << " ] it's not alive" << endl;
39+ };
40+
41+ print_func (" A" ); // ! it's alive, value 10
42+ delete tmp;
43+
44+ print_func (" B" ); // ! it's not alive
45+
46+ return 0 ;
47+ }
Original file line number Diff line number Diff line change 2020#ifndef TBOX_LIFETIME_TAG_H_20221215
2121#define TBOX_LIFETIME_TAG_H_20221215
2222
23+ #include < utility>
24+
2325namespace tbox {
2426
2527/* *
Original file line number Diff line number Diff line change 2121# TBOX版本号
2222TBOX_VERSION_MAJOR := 1
2323TBOX_VERSION_MINOR := 13
24- TBOX_VERSION_REVISION := 6
24+ TBOX_VERSION_REVISION := 7
You can’t perform that action at this time.
0 commit comments