From 0cf4fea1ff6fc37118638a616c9f6e95b19451f0 Mon Sep 17 00:00:00 2001
From: levlam <levlam@telegram.org>
Date: Mon, 15 Jun 2020 04:52:56 +0300
Subject: [PATCH] Remove enum usages for static constants creation.

GitOrigin-RevId: 2a88fd2cd961398a09403fe35a15ae56372a44f8
---
 benchmark/bench_log.cpp               | 16 ++++++++--------
 benchmark/bench_queue.cpp             |  2 +-
 td/mtproto/AuthKey.h                  |  4 +++-
 tdutils/td/utils/BufferedUdp.h        |  5 +++--
 tdutils/td/utils/port/UdpSocketFd.cpp |  3 ++-
 5 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/benchmark/bench_log.cpp b/benchmark/bench_log.cpp
index afc23e9a9..63807b2fd 100644
--- a/benchmark/bench_log.cpp
+++ b/benchmark/bench_log.cpp
@@ -40,8 +40,8 @@ class IostreamWriteBench : public td::Benchmark {
  protected:
   std::string file_name_;
   std::ofstream stream;
-  enum { buffer_size = 1 << 20 };
-  char buffer[buffer_size];
+  static constexpr std::size_t BUFFER_SIZE = 1 << 20;
+  char buffer[BUFFER_SIZE];
 
  public:
   std::string get_description() const override {
@@ -52,7 +52,7 @@ class IostreamWriteBench : public td::Benchmark {
     file_name_ = create_tmp_file();
     stream.open(file_name_.c_str());
     CHECK(stream.is_open());
-    //    stream.rdbuf()->pubsetbuf(buffer, buffer_size);
+    //    stream.rdbuf()->pubsetbuf(buffer, BUFFER_SIZE);
   }
 
   void run(int n) override {
@@ -71,8 +71,8 @@ class FILEWriteBench : public td::Benchmark {
  protected:
   std::string file_name_;
   FILE *file;
-  enum { buffer_size = 1 << 20 };
-  char buffer[buffer_size];
+  static constexpr std::size_t BUFFER_SIZE = 1 << 20;
+  char buffer[BUFFER_SIZE];
 
  public:
   std::string get_description() const override {
@@ -82,7 +82,7 @@ class FILEWriteBench : public td::Benchmark {
   void start_up() override {
     file_name_ = create_tmp_file();
     file = fopen(file_name_.c_str(), "w");
-    //    setvbuf(file, buffer, _IOFBF, buffer_size);
+    //    setvbuf(file, buffer, _IOFBF, BUFFER_SIZE);
   }
 
   void run(int n) override {
@@ -123,8 +123,8 @@ class LogWriteBench : public td::Benchmark {
   std::string file_name_;
   std::ofstream stream;
   std::streambuf *old_buf;
-  enum { buffer_size = 1 << 20 };
-  char buffer[buffer_size];
+  static constexpr std::size_t BUFFER_SIZE = 1 << 20;
+  char buffer[BUFFER_SIZE];
 
  public:
   std::string get_description() const override {
diff --git a/benchmark/bench_queue.cpp b/benchmark/bench_queue.cpp
index d22b1247e..af5f48c32 100644
--- a/benchmark/bench_queue.cpp
+++ b/benchmark/bench_queue.cpp
@@ -837,7 +837,7 @@ class QueueBenchmark : public td::Benchmark {
 
 template <class QueueT>
 class RingBenchmark : public td::Benchmark {
-  enum { QN = 504 };
+  static constexpr int QN = 504;
 
   struct Thread {
     int int_id;
diff --git a/td/mtproto/AuthKey.h b/td/mtproto/AuthKey.h
index 443eda994..e35121f9d 100644
--- a/td/mtproto/AuthKey.h
+++ b/td/mtproto/AuthKey.h
@@ -66,7 +66,9 @@ class AuthKey {
     auth_key_.clear();
   }
 
-  enum : int32 { AUTH_FLAG = 1, WAS_AUTH_FLAG = 2, HAS_CREATED_AT = 4 };
+  static constexpr int32 AUTH_FLAG = 1;
+  static constexpr int32 WAS_AUTH_FLAG = 2;
+  static constexpr int32 HAS_CREATED_AT = 4;
 
   template <class StorerT>
   void store(StorerT &storer) const {
diff --git a/tdutils/td/utils/BufferedUdp.h b/tdutils/td/utils/BufferedUdp.h
index 92c5b7635..68031dc29 100644
--- a/tdutils/td/utils/BufferedUdp.h
+++ b/tdutils/td/utils/BufferedUdp.h
@@ -64,7 +64,8 @@ class UdpReaderHelper {
   }
 
  private:
-  enum : size_t { MAX_PACKET_SIZE = 2048, RESERVED_SIZE = MAX_PACKET_SIZE * 8 };
+  static constexpr size_t MAX_PACKET_SIZE = 2048;
+  static constexpr size_t RESERVED_SIZE = MAX_PACKET_SIZE * 8;
   UdpMessage message_;
   BufferSlice buffer_;
 };
@@ -98,7 +99,7 @@ class UdpReader {
   }
 
  private:
-  enum : size_t { BUFFER_SIZE = 16 };
+  static constexpr size_t BUFFER_SIZE = 16;
   std::array<UdpSocketFd::InboundMessage, BUFFER_SIZE> messages_;
   std::array<UdpReaderHelper, BUFFER_SIZE> helpers_;
 };
diff --git a/tdutils/td/utils/port/UdpSocketFd.cpp b/tdutils/td/utils/port/UdpSocketFd.cpp
index 5b25b6132..bd0efcff2 100644
--- a/tdutils/td/utils/port/UdpSocketFd.cpp
+++ b/tdutils/td/utils/port/UdpSocketFd.cpp
@@ -170,7 +170,8 @@ class UdpSocketFdImpl : private Iocp::Callback {
   UdpMessage to_receive_;
   WSAMSG receive_message_;
   UdpSocketReceiveHelper receive_helper_;
-  enum : size_t { MAX_PACKET_SIZE = 2048, RESERVED_SIZE = MAX_PACKET_SIZE * 8 };
+  static constexpr size_t MAX_PACKET_SIZE = 2048;
+  static constexpr size_t RESERVED_SIZE = MAX_PACKET_SIZE * 8;
   BufferSlice receive_buffer_;
 
   UdpMessage to_send_;