Bug 1605894 reduce the proliferation of DefaultLoopbackTone to only AudioStreamFlowin...
[gecko.git] / mfbt / fallible.h
blobfabb54e82a7e4a4d3ef493e09d6d304ebb3be0f9
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef mozilla_fallible_h
6 #define mozilla_fallible_h
8 #if defined(__cplusplus)
10 /* Explicit fallible allocation
12 * Memory allocation (normally) defaults to abort in case of failed
13 * allocation. That is, it never returns NULL, and crashes instead.
15 * Code can explicitely request for fallible memory allocation thanks
16 * to the declarations below.
18 * The typical use of the mozilla::fallible const is with placement new,
19 * like the following:
21 * foo = new (mozilla::fallible) Foo();
23 * The following forms, or derivatives, are also possible but deprecated:
25 * foo = new ((mozilla::fallible_t())) Foo();
27 * const mozilla::fallible_t f = mozilla::fallible_t();
28 * bar = new (f) Bar();
30 * It is also possible to declare method overloads with fallible allocation
31 * alternatives, like so:
33 * class Foo {
34 * public:
35 * void Method(void *);
36 * void Method(void *, const mozilla::fallible_t&);
37 * };
39 * Foo foo;
40 * foo.Method(nullptr, mozilla::fallible);
42 * If that last method call is in a method that itself takes a const
43 * fallible_t& argument, it is recommended to propagate that argument
44 * instead of using mozilla::fallible:
46 * void Func(Foo &foo, const mozilla::fallible_t& aFallible) {
47 * foo.Method(nullptr, aFallible);
48 * }
52 # include <new>
54 namespace mozilla {
56 using fallible_t = std::nothrow_t;
58 static const fallible_t& fallible = std::nothrow;
60 } // namespace mozilla
62 #endif
64 #endif // mozilla_fallible_h