Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The question about stream template functions in sliced-integer.hxx #3

Closed
NanXiao opened this issue Jan 4, 2018 · 2 comments
Closed

Comments

@NanXiao
Copy link
Contributor

NanXiao commented Jan 4, 2018

Hi all,

The template istream and ostream functions defined in sliced-integer.hxx:

/*! \brief implementation of the formatted read operation */
template<typename BitType>
std::istream& operator>>
  (std::istream &in_io,
   BitType &value_o)
{
  value_o.read (in_io);
  return in_io;
}

/*! \brief implementation of the formatted write operation */
template<typename BitType>
std::ostream& operator<<
  (std::ostream &out_io,
   const BitType &value_i)
{
  value_i.write (out_io);
  return out_io;
}

will cause build error when source code who includes sliced-integer.hxx and do input and output some basic data types, such as string. For example:

#include <integer.hxx>
......
string a;
cout << a;

Compile it:

error: ambiguous overload for ‘operator<<’ (operand types are ‘std::ostream {aka std::basic_ostream<char>}’ and ‘std::__cxx11::string {aka std::__cxx11::basic_string<char>}’)
  cout << a;
  ~~~~~^~~~
In file included from /home/xiaonan/Cingulata/circuit/generator/src/../include/integer.hxx:30:0,
                 from /home/xiaonan/Cingulata/tests/trivium/trivium.cxx:25:
/home/xiaonan/Cingulata/circuit/generator/src/../include/sliced-integer.hxx:312:15: note: candidate: std::ostream& operator<<(std::ostream&, const BitType&) [with BitType = std::__cxx11::basic_string<char>; std::ostream = std::basic_ostream<char>]
 std::ostream& operator<<
               ^~~~~~~~
In file included from /usr/include/c++/7.2.1/string:52:0,
                 from /usr/include/c++/7.2.1/bits/locale_classes.h:40,
                 from /usr/include/c++/7.2.1/bits/ios_base.h:41,
                 from /usr/include/c++/7.2.1/ios:42,
                 from /usr/include/c++/7.2.1/ostream:38,
                 from /usr/include/c++/7.2.1/iostream:39,
                 from /home/xiaonan/Cingulata/tests/trivium/trivium.cxx:22:
/usr/include/c++/7.2.1/bits/basic_string.h:6272:5: note: candidate: std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]
     operator<<(basic_ostream<_CharT, _Traits>& __os,

Similar for input string:

string a;
cin >> a;

So is it really necessary to define these two template functions?

Thanks very much!

Best Regards
Nan Xiao

@renaud-sirdey
Copy link
Collaborator

Dear Nan,

This is connected to my latter comment on issue #2.

In a Cingulata program, any value not read from the standard input into IntegerX variables would be considered constant and triggers simplifications in the resulting boolean circuit. For this reason, it is necessary to avoid IOs on any other types and to define clear-domain constant values explictly into the program.

Still, clear-domain values may still be passed through IOs on IntegerX type (perhaps a tutorial is needed to explain how to do these more advanced IOs, we’ll work on this soon) and in this case do not influence the structure of the circuit.

Hope this helps!

Best regards, Renaud

@NanXiao
Copy link
Contributor Author

NanXiao commented Jan 9, 2018

Hi Renaud,

Got it! Thanks very much for your time and help!

Best Regards
Nan Xiao

@NanXiao NanXiao closed this as completed Jan 9, 2018
sergiu-carpov pushed a commit that referenced this issue Jun 13, 2019
…ter'

Resolve "Implement multiplication operator"

Closes #3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants