Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Why use an implicit conversion from (std::string) to (void) type?

I'm looking at CPP-NETLIB's source code and came across this syntax where it describes the concepts.

template <class R> struct ClientRequest : network::Message<R> {
  BOOST_CONCEPT_USAGE(ClientRequest) {
    std::string tmp;
    R request_(tmp);
    swap(request, request_);  // swappable via ADL

    std::string host_ = host(request);
    boost::uint16_t port_ = port(request);
    std::string path_ = path(request);
    std::string query_ = query(request);
    std::string anchor_ = anchor(request);
    std::string protocol_ = protocol(request);

    request << uri(std::string());

    network::http::uri(request, std::string());

    (void) host_;
    (void) port_;
    (void) path_;
    (void) query_;
    (void) anchor_;
    (void) protocol_;
  }

 private:
  R request;
};

I can't seem to find any explanations that describe how the (void) conversion of in-scope types could be necessary or what it would do. Why would you need to clear the stack before ending the BOOST_CONCEPT_USAGE member function? What else would it do if not clearing the stack?

like image 613
etcimon Avatar asked Sep 20 '13 13:09

etcimon


People also ask

Why are implicit conversions possible in C?

Implicit type conversion in C happens automatically when a value is copied to its compatible data type. During conversion, strict rules for type conversion are applied. If the operands are of two different data types, then an operand having lower data type is automatically converted into a higher data type.

Is implicit type conversion bad?

Implicit conversions allow the compiler to treat values of a type as values of another type. There's at least one set of scenarios in which this is unambiguously bad: non-total conversions. That is, converting an A to a B when there exists A s for which this conversion is impossible.

What happens in implicit conversion?

An implicit conversion sequence is the sequence of conversions required to convert an argument in a function call to the type of the corresponding parameter in a function declaration. The compiler tries to determine an implicit conversion sequence for each argument.

What is implicit data type conversion?

Implicit type conversion in C language is the conversion of one data type into another datatype by the compiler during the execution of the program. It is also called automatic type conversion.


1 Answers

It's just for suppressing the compiler's warnings about unused variable, nothing special.

It does NOT clear the stack in any way, if that's what you mean.

like image 140
Kiril Kirov Avatar answered Nov 15 '22 08:11

Kiril Kirov