Skip to content
This repository was archived by the owner on Jun 12, 2018. It is now read-only.
This repository was archived by the owner on Jun 12, 2018. It is now read-only.

C++17 string_view #213

@SethHamilton

Description

@SethHamilton

using string_view = const std::string &; // TODO c++17: use std::string_view

I changed this line to:

using string_view = std::string_view;

and life became wonderful. My application keeps data in char* format (with a known size_t). I was pushing these char* buffers into streams, and passing them to request. I realized that this results in 2 copies of the data (one to create my stream, and another request uses << to push that stream into ASIO).

string_view solves this wonderfully, as it simply wraps the pointer and length, and results in one less copy (some of my transfers are over 100mb, making copies painful and memory intensive).

I realize your original code comment might have to do with C++17 feature detection, but I think this can be cured with the following:

#ifdef __has_include 
  #if __has_include(<string_view>)
    #include<string_view>
    using string_view = std::string_view;
    #define __has_string_view 1
  #endif
#endif
#ifndef __has_string_view
  using string_view = const std::string &;
#endif

Super-ultra-nice would be versions of request that took a char* and a size_t, I could see this being a super common use case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions