-
Notifications
You must be signed in to change notification settings - Fork 47
/
safebool.h
executable file
·47 lines (38 loc) · 1.26 KB
/
safebool.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/***
*safebool.h - types and constants for implementing the "smart bool" idiom.
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
*Purpose: Prefer _safe_bool to an implicit conversion to bool. When a
* type is implicitly convertible to bool, it is also implicitly
* convertible to any integral type, and this is often not
* desired. Instead, provide a conversion to _safe_bool, which
* is really a pointer to a member function on a dummy struct.
* This pointer can be evaluated in Boolean context, but it will
* never be converted to an integral type.
*
* [Public]
*
****/
#pragma once
#if !defined (_INC_MSCLR_SAFEBOOL)
#ifndef __cplusplus_cli
#error ERROR: msclr libraries are not compatible with /clr:oldSyntax
#endif /* __cplusplus_cli */
namespace msclr
{
value class _detail_class
{
public:
value class dummy_struct
{
public:
static initonly System::String^ dummy_string = "";
};
typedef System::String^ _safe_bool;
static _safe_bool const _safe_true = dummy_struct::dummy_string;
static _safe_bool const _safe_false = nullptr;
};
}
#define _INC_MSCLR_SAFEBOOL
#endif /* !defined (_INC_MSCLR_SAFEBOOL) */