Skip to content

Conversation

@reuk
Copy link

@reuk reuk commented Dec 1, 2017

No description provided.

romainbrenguier and others added 10 commits December 1, 2017 06:57
This allows to extend numeric_cast to other argument types than mp_integer.
This returns a value instead of an optional but an invariant can fail.
numeric_cast can now be used instead.
This is to demonstrate the use of numeric_cast
std::numeric_limits methods are not declared constexpr in old versions
of VS so we need to replace them by preconditions

optionalt<T> operator()(const mp_integer &mpi) const
{
constexpr const auto precondition =
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surely this will be a static error on VS2013 which doesn't have constexprs in the standard library

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, potentially yeah. You could put an ifdef around the constexpr I suppose, or we might have a macro that conditionally expands to constexpr in util somewhere.

static optionalt<T> numeric_cast(const mp_integer &mpi)
template <typename U = T,
typename std::enable_if<std::is_signed<U>::value, int>::type = 0>
static auto get_val(const mp_integer &mpi) -> decltype(mpi.to_long())
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should both be private

Copy link
Owner

@romainbrenguier romainbrenguier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the proposal. What I don't find nice is that we pull a lot of things from arith_tools to mp_arith which I think we want to keep seperate. Could we instead define these numeric_cast things in a new file?


const mp_integer mp_zero=string2integer("0");

class exprt;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate of line 23?

@reuk
Copy link
Author

reuk commented Dec 3, 2017

The problem is that I think all the numeric cast overloads need to be defined in one go. So as long as all the numeric_cast definitions are moved, that will work, but moving just a few of them won't

@romainbrenguier romainbrenguier force-pushed the refactor/expr_cast_to_util branch 2 times, most recently from d69a2dd to 7fbfeec Compare December 4, 2017 14:12
@reuk
Copy link
Author

reuk commented Dec 4, 2017

I'm not sure what to do with this branch. I don't plan to work on it any more, as all the suggested changes are very minor. I'd suggest that you cherry-pick any changes you like (if any) and close it once you've extracted anything useful.

@romainbrenguier
Copy link
Owner

@reuk

I'm not sure what to do with this branch. I don't plan to work on it any more, as all the suggested changes are very minor. I'd suggest that you cherry-pick any changes you like (if any) and close it once you've extracted anything useful.

Yes no problem, I already integrated some of the changes in my branch. Just leave this open in case there are other changes I could use.

@romainbrenguier romainbrenguier force-pushed the refactor/expr_cast_to_util branch 6 times, most recently from 70598c4 to 9a811d8 Compare December 8, 2017 13:12
@reuk reuk closed this Jan 23, 2018
romainbrenguier pushed a commit that referenced this pull request Mar 22, 2019
We should keep the struct tag type, not follow it and get the struct type
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

Successfully merging this pull request may close these issues.

3 participants