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