Advertisement
honey_the_codewitch

can't overload operator explicit with float arg

Oct 29th, 2024 (edited)
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.48 KB | None | 0 0
  1. #ifndef HTCW_GFX_POSITIONING_HPP
  2. #define HTCW_GFX_POSITIONING_HPP
  3. #include "gfx_core.hpp"
  4. #include <htcw_bits.hpp>
  5. namespace gfx {
  6. ...
  7.     // represents a size with integer coordinates
  8.     template <typename T>
  9.     struct sizex final {
  10.         using type = sizex;
  11.         using value_type = T;
  12.         // the width
  13.         T width;
  14.         // the height
  15.         T height;
  16.         // constructs a new instance
  17.         inline sizex() {}
  18.         // constructs a new instance with the specified width and height
  19.         constexpr inline sizex(T width, T height) : width(width), height(height) {
  20.         }
  21.         // increases or decreases the width and height by the specified amounts.
  22.         constexpr sizex inflate(typename bits::signedx<T> width,typename bits::signedx<T> height) const {
  23.             return sizex(width+this->width,height+this->height);
  24.         }
  25.         constexpr inline rectx<T> bounds() const;
  26.         constexpr explicit operator sizex<bits::signedx<value_type>>() const {
  27.             return sizex<bits::signedx<value_type>>(bits::signedx<value_type>(width),bits::signedx<value_type>(height));
  28.         }
  29.         constexpr explicit operator sizex<bits::unsignedx<value_type>>() const {
  30.             return sizex<bits::unsignedx<value_type>>(bits::unsignedx<value_type>(width),bits::unsignedx<value_type>(height));
  31.         }
  32.  
  33.         // won't compile"
  34.         constexpr inline explicit operator sizex<float>() const {
  35.             return sizex<float>(float(width),float(height));
  36.         }
  37.        
  38.         constexpr inline bool operator==(const sizex& rhs) const {
  39.             return width==rhs.width && height==rhs.height;  
  40.         }
  41.         constexpr inline bool operator!=(const sizex& rhs) const {
  42.             return width!=rhs.width || height!=rhs.height;
  43.         }
  44.         constexpr static const inline sizex min() { return { bits::num_metrics<value_type>::min,bits::num_metrics<value_type>::min }; }
  45.         constexpr static const inline sizex max() { return { bits::num_metrics<value_type>::max,bits::num_metrics<value_type>::max }; }
  46.  
  47.         constexpr inline float aspect_ratio() const {
  48.             return (float)width/(float)height;
  49.         }
  50.  
  51.         constexpr size_t area() const {
  52.             return width*height;
  53.         }
  54.         constexpr sizex flip() const {
  55.             return {height,width};
  56.         }
  57.         constexpr static const inline sizex zero() { return { bits::num_metrics<value_type>::zero,bits::num_metrics<value_type>::zero }; }
  58. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement