Skip to content

Commit c8f7914

Browse files
committed
feat(base):1.13.7, 添加了LifetimeTag的example示例
1 parent 85c7bc0 commit c8f7914

4 files changed

Lines changed: 79 additions & 1 deletion

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
}

modules/base/lifetime_tag.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#ifndef TBOX_LIFETIME_TAG_H_20221215
2121
#define TBOX_LIFETIME_TAG_H_20221215
2222

23+
#include <utility>
24+
2325
namespace tbox {
2426

2527
/**

version.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121
# TBOX版本号
2222
TBOX_VERSION_MAJOR := 1
2323
TBOX_VERSION_MINOR := 13
24-
TBOX_VERSION_REVISION := 6
24+
TBOX_VERSION_REVISION := 7

0 commit comments

Comments
 (0)