private_constructor.h 1.1 KB

123456789101112131415161718192021222324252627282930
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef __PRIVATE_CONSTRUCTOR__H
  9. #define __PRIVATE_CONSTRUCTOR__H
  10. #include <iostream>
  11. struct PrivateConstructor {
  12. PrivateConstructor static make ( int v ) { return PrivateConstructor(v); }
  13. int get () const { return val; }
  14. private:
  15. PrivateConstructor ( int v ) : val(v) {}
  16. int val;
  17. };
  18. bool operator < ( const PrivateConstructor &lhs, const PrivateConstructor &rhs ) { return lhs.get() < rhs.get(); }
  19. bool operator < ( const PrivateConstructor &lhs, int rhs ) { return lhs.get() < rhs; }
  20. bool operator < ( int lhs, const PrivateConstructor &rhs ) { return lhs < rhs.get(); }
  21. std::ostream & operator << ( std::ostream &os, const PrivateConstructor &foo ) { return os << foo.get (); }
  22. #endif