You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
767 B
36 lines
767 B
2 years ago
|
#include <cstdio>
|
||
|
#include <unistd.h>
|
||
|
|
||
|
#include "../include/opaque.hh"
|
||
|
|
||
|
|
||
|
static void print_view(std::string_view ptr)
|
||
|
{
|
||
|
//std::string_view ptr{string};
|
||
|
|
||
|
size_t sz;
|
||
|
#if DIRECT_WRITE
|
||
|
if(__builtin_expect((sz = ptr.size()) > 0, true)) {
|
||
|
write(1, "> ", 2);
|
||
|
write(1, ptr.data(), sz);
|
||
|
} else write(1, "! <null>\n", 8);
|
||
|
write(1, "\n", 1);
|
||
|
#else
|
||
|
if(__builtin_expect((sz = ptr.size()) > 0, true)) {
|
||
|
printf("> %.*s\n", (int)sz, ptr.data());
|
||
|
} else puts("! <null>\n");
|
||
|
#endif
|
||
|
}
|
||
|
static inline void print(const std::string& string)
|
||
|
{
|
||
|
std::string_view sv{string};
|
||
|
return print_view(sv);
|
||
|
}
|
||
|
|
||
|
int main()
|
||
|
{
|
||
|
const opaque_handle v{make_opaque_object_handle(std::string{"Hello world"})};
|
||
|
print(*v); //XXX: Why does converting it to string_view here break it?
|
||
|
return 0;
|
||
|
}
|