c++ - Designing an API to accept a generic output stream as a parameter -


i designing api using llvm library accept output stream 1 of constructor parameters. llvm coding standards dictate following:

use raw_ostream

llvm includes lightweight, simple, , efficient stream implementation in llvm/support/raw_ostream.h, provides of common features of std::ostream. new code should use raw_ostream instead of ostream.

unlike std::ostream, raw_ostream not template , can forward declared class raw_ostream. public headers should not include raw_ostream header, use forward declarations , constant references raw_ostream instances.

i must abide llvm coding standards, trying accept raw_ostream parameter in constructor. have tried passing raw_ostream reference , pointer, receive following error message @ compile time:

note: candidate constructor not viable: no known conversion 'llvm::raw_ostream &()' 'llvm::raw_ostream &'...

what should constructor accept parameter of type 'llvm::raw_ostream &()'? initialize class member output stream.

here current code:

constructor

myclass(raw_ostream &os) : outputstream(os) {} 

caller

myclass x = new myclass(&outs); 

outs documented beginning @ line 665 of this link

there tons of examples within llvm source raw_ostream function / method argument. it's (..., raw_ostream &os, ...)

here's representative example codegen/asmprinter/asmprinter.cpp:

static void emitcomments(const machineinstr &mi, raw_ostream &commentos) {   // ... code } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -