Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. #include <utility>
  2. #include <memory>
  3. #include <cstdio>
  4.  
  5. template<auto F> struct caller {
  6. template<class... Ts>
  7. auto operator()(Ts&&... ts) const
  8. noexcept(noexcept(F(std::forward<Ts>(ts)...)))
  9. {
  10. return F(std::forward<Ts>(ts)...);
  11. }
  12. };
  13.  
  14. int main()
  15. {
  16. using fileptr = std::unique_ptr<std::FILE, caller<std::fclose>>;
  17. static_assert(sizeof(fileptr) == sizeof(FILE*));
  18. fileptr ptr(std::fopen("xyz.txt", "w"));
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement