Skip to content

Commit 11144d6

Browse files
committed
Added scl namespacing
1 parent e97560d commit 11144d6

File tree

7 files changed

+22
-19
lines changed

7 files changed

+22
-19
lines changed

include/scl/sync_send.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <mutex>
99
#include <atomic>
1010

11+
namespace scl {
1112
/**
1213
A wrapper that can be used around pointers to allow the this pointer to be passed.
1314
There's nothing special about this, it's just a dump pointer but means we can
@@ -231,3 +232,5 @@ static_assert(! is_sync_v<const int&>);
231232
static_assert(! is_sync_v<std::string&>);
232233
static_assert(! is_sync_v<const std::string&>);
233234
static_assert(is_sync_v<std::atomic<int>>);
235+
236+
}

include/scl/synchronized_value.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include "sync_send.h"
99

10-
10+
namespace scl {
1111
template<typename Type>
1212
class synchronized_value
1313
{
@@ -43,3 +43,5 @@ struct is_send<synchronized_value<T>&> : std::true_type {};
4343

4444
template<typename T>
4545
struct is_sync<synchronized_value<T>> : std::true_type {};
46+
47+
}

include/scl/syncronized_value.test.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <cassert>
33
#include "synchronized_value.h"
44

5-
synchronized_value<std::string> s;
5+
scl::synchronized_value<std::string> s;
66

77
std::string read_value() {
88
return apply([](auto &x) { return x; }, s);
@@ -18,7 +18,7 @@ void test_single() {
1818
}
1919

2020
void test_multi() {
21-
synchronized_value<int> a(1), b(2), c(3);
21+
scl::synchronized_value<int> a(1), b(2), c(3);
2222
int sum = apply([](auto &...ints) { return (ints++ + ...); }, a, b, c);
2323
assert(sum == 6);
2424
auto get = [](int &i) { return i; };
@@ -37,9 +37,9 @@ struct person
3737
};
3838

3939
template<>
40-
struct is_sync<person> : std::true_type {};
40+
struct scl::is_sync<person> : std::true_type {};
4141

42-
static_assert(is_send_v<person>);
42+
static_assert(scl::is_send_v<person>);
4343

4444
int main()
4545
{

tests/pass_copy_reference.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ static_assert(! std::is_object_v<decltype(entry_point)>);
1616
static_assert(! std::is_member_function_pointer_v<decltype(entry_point)>);
1717
static_assert(! std::is_pointer_v<decltype(entry_point)>);
1818

19-
static_assert(is_function_pointer_v<std::decay_t<decltype(entry_point)>>
19+
static_assert(scl::is_function_pointer_v<std::decay_t<decltype(entry_point)>>
2020
&& ! std::is_member_function_pointer_v<decltype(entry_point)>);
21-
static_assert(is_function_pointer_v<std::decay_t<decltype(entry_point)>>
21+
static_assert(scl::is_function_pointer_v<std::decay_t<decltype(entry_point)>>
2222
&& ! std::is_member_function_pointer_v<decltype(entry_point)>);
2323

2424
int main()

tests/pass_move_reference.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ void entry_point (int tid)
1313

1414
using T = decltype(entry_point);
1515
static_assert (std::is_pointer_v<std::remove_extent_t<std::decay_t<T>>>);
16-
static_assert (is_function_pointer_v<std::decay_t<T>>);
16+
static_assert (scl::is_function_pointer_v<std::decay_t<T>>);
1717
static_assert (! (std::is_pointer_v<std::remove_extent_t<std::decay_t<T>>>
18-
&& ! is_function_pointer_v<std::decay_t<T>>));
18+
&& ! scl::is_function_pointer_v<std::decay_t<T>>));
1919
static_assert (! std::is_member_function_pointer_v<T>);
2020

2121
static_assert (! std::is_move_constructible_v<T>);
22-
static_assert (is_function_pointer_v<std::decay_t<T>>
22+
static_assert (scl::is_function_pointer_v<std::decay_t<T>>
2323
&& ! std::is_member_function_pointer_v<std::decay_t<T>>);
24-
static_assert (! is_sync_v<T>);
24+
static_assert (! scl::is_sync_v<T>);
2525

2626
static_assert(std::is_function_v<void (int)>);
2727
static_assert(std::is_function_v<std::remove_cvref_t<void (&)(int)>>);

tests/pass_shared_syncronised_string.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
using namespace std::literals;
99

10-
void entry_point (std::shared_ptr<synchronized_value<std::string>> sync_s, int tid)
10+
void entry_point (std::shared_ptr<scl::synchronized_value<std::string>> sync_s, int tid)
1111
{
1212
apply ( [tid] (auto& s) {
1313
s.append ("🔥");
@@ -17,18 +17,18 @@ void entry_point (std::shared_ptr<synchronized_value<std::string>> sync_s, int t
1717
*sync_s);
1818
}
1919

20-
static_assert(is_function_pointer_v<std::decay_t<decltype(entry_point)>>);
20+
static_assert(scl::is_function_pointer_v<std::decay_t<decltype(entry_point)>>);
2121
static_assert(! std::is_member_function_pointer_v<std::decay_t<decltype(entry_point)>>);
2222
static_assert(! std::is_member_function_pointer_v<decltype(entry_point)>);
23-
static_assert(is_send_v<decltype(entry_point)>);
23+
static_assert(scl::is_send_v<decltype(entry_point)>);
2424

2525
int main()
2626
{
2727
std::vector<scl::thread> threads { };
2828

2929
{
3030
//s dies before the threads join, so possible
31-
auto s = std::make_shared<synchronized_value<std::string>> ("Hello threads");
31+
auto s = std::make_shared<scl::synchronized_value<std::string>> ("Hello threads");
3232

3333
// Launch all threads.
3434
const int num_threads = 15;

tests/pass_thread_runner.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,16 @@
55

66
using namespace std::literals;
77

8-
9-
108
class thread_runner
119
{
1210
public:
1311
thread_runner()
1412
{
15-
std::mem_fn (&thread_runner::run) (unchecked_pointer<thread_runner> (this));
13+
std::mem_fn (&thread_runner::run) (scl::unchecked_pointer<thread_runner> (this));
1614

1715
// static_assert(is_send_v<decltype(std::mem_fn (&thread_runner::run))>);
1816
// static_assert(is_send_v<std::decay_t<decltype(std::mem_fn (&thread_runner::run))>>);
19-
thread = std::make_unique<scl::thread> (std::mem_fn (&thread_runner::run), unchecked_pointer (this));
17+
thread = std::make_unique<scl::thread> (std::mem_fn (&thread_runner::run), scl::unchecked_pointer (this));
2018
// thread = std::make_unique<safe_thread> (std::mem_fn (&thread_runner::run), this_wrapper<const thread_runner> (const_cast<const thread_runner*> (this)));
2119
// thread = std::make_unique<safe_thread> (std::mem_fn (&thread_runner::run), const_cast<const thread_runner*> (this));
2220
}

0 commit comments

Comments
 (0)