diff --git a/intern/mantaflow/intern/MANTA_main.cpp b/intern/mantaflow/intern/MANTA_main.cpp
index b9552c82335cc20062bcd266b327747df0a9bb67..66e27310d3eb205e1fa555dba572594f8aea5316 100644
--- a/intern/mantaflow/intern/MANTA_main.cpp
+++ b/intern/mantaflow/intern/MANTA_main.cpp
@@ -6,6 +6,7 @@
  * \ingroup intern_mantaflow
  */
 
+#include <algorithm>
 #include <fstream>
 #include <iomanip>
 #include <iostream>
@@ -830,7 +831,7 @@ void MANTA::initializeRNAMap(FluidModifierData *fmd)
   string cacheDirectory(fds->cache_directory);
 
   float viscosity = fds->viscosity_base * pow(10.0f, -fds->viscosity_exponent);
-  float domainSize = MAX3(fds->global_size[0], fds->global_size[1], fds->global_size[2]);
+  float domainSize = std::max({fds->global_size[0], fds->global_size[1], fds->global_size[2]});
 
   string vdbCompressionMethod = "Compression_None";
   if (fds->openvdb_compression == VDB_COMPRESSION_NONE) {
diff --git a/source/blender/blenfont/intern/blf_thumbs.cc b/source/blender/blenfont/intern/blf_thumbs.cc
index de7534a557e437823823e7f8ba7ebbe00de3f74a..132e74c907cc1e12eebc03b243e67150509ce3af 100644
--- a/source/blender/blenfont/intern/blf_thumbs.cc
+++ b/source/blender/blenfont/intern/blf_thumbs.cc
@@ -10,6 +10,7 @@
  * Isolate since this needs to be called by #ImBuf code (bad level call).
  */
 
+#include <algorithm>
 #include <cstdlib>
 
 #include <ft2build.h>
@@ -368,9 +369,9 @@ bool BLF_thumb_preview(const char *filename, uchar *buf, int w, int h, int /*cha
   width = std::max(width, height);
 
   /* Fill up to 96% horizontally or vertically. */
-  float font_size = MIN3(float(w),
-                         (float(w) * 0.96f / float(width) * float(w)),
-                         float(h) * 0.96f / float(height) * float(h));
+  float font_size = std::min({float(w),
+                              (float(w) * 0.96f / float(width) * float(w)),
+                              float(h) * 0.96f / float(height) * float(h)});
 
   if (font_size < 1 || FT_Set_Char_Size(face, int(font_size * 64.0f), 0, 72, 72) != FT_Err_Ok) {
     /* Sizing can fail, but very rarely. */
diff --git a/source/blender/blenkernel/BKE_cryptomatte.hh b/source/blender/blenkernel/BKE_cryptomatte.hh
index 6435b87df64ecc92653b13611c4d1d0ad9c649ee..c663d97f7f8da734181f1a0ff59e7b7e85d4727f 100644
--- a/source/blender/blenkernel/BKE_cryptomatte.hh
+++ b/source/blender/blenkernel/BKE_cryptomatte.hh
@@ -8,6 +8,7 @@
 
 #pragma once
 
+#include <algorithm>
 #include <optional>
 #include <string>
 
@@ -80,8 +81,8 @@ struct CryptomatteHash {
   {
     uint32_t mantissa = hash & ((1 << 23) - 1);
     uint32_t exponent = (hash >> 23) & ((1 << 8) - 1);
-    exponent = MAX2(exponent, uint32_t(1));
-    exponent = MIN2(exponent, uint32_t(254));
+    exponent = std::max(exponent, uint32_t(1));
+    exponent = std::min(exponent, uint32_t(254));
     exponent = exponent << 23;
     uint32_t sign = (hash >> 31);
     sign = sign << 31;
diff --git a/source/blender/blenkernel/intern/blendfile_link_append.cc b/source/blender/blenkernel/intern/blendfile_link_append.cc
index 8f7056bbc3ad3bb811fc45c0edb4b52695042bd2..c33ffd1167990955fa00bf5beaf4b1e3d51e0c8a 100644
--- a/source/blender/blenkernel/intern/blendfile_link_append.cc
+++ b/source/blender/blenkernel/intern/blendfile_link_append.cc
@@ -10,6 +10,7 @@
  * collections/objects/object-data in current scene.
  */
 
+#include <algorithm>
 #include <cstdlib>
 #include <cstring>
 
@@ -1656,7 +1657,7 @@ static void blendfile_library_relocate_remap(Main *bmain,
       old_id->name[dot_pos] = '~';
     }
     else {
-      len = MIN2(len, MAX_ID_NAME - 7);
+      len = std::min<size_t>(len, MAX_ID_NAME - 7);
       BLI_strncpy(&old_id->name[len], "~000", 7);
     }
 
diff --git a/source/blender/blenkernel/intern/boids.cc b/source/blender/blenkernel/intern/boids.cc
index 67d9c447da6ee4d537c78836a616ea7a568706a5..c3157334d5a5eb91bf99f06971187d917165267b 100644
--- a/source/blender/blenkernel/intern/boids.cc
+++ b/source/blender/blenkernel/intern/boids.cc
@@ -1181,7 +1181,7 @@ void boid_brain(BoidBrainData *bbd, int p, ParticleData *pa)
           if (len < val.jump_speed * mul || bbd->part->boids->options & BOID_ALLOW_FLIGHT) {
             jump = 1;
 
-            len = MIN2(len, val.jump_speed);
+            len = std::min(len, val.jump_speed);
 
             copy_v3_v3(jump_v, dir);
             jump_v[2] = z_v;
@@ -1320,7 +1320,7 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa)
     old_speed = len_v3(pa->prev_state.vel);
 
     if (bbd->wanted_speed < old_speed) {
-      new_speed = MAX2(bbd->wanted_speed, old_speed - val.max_acc);
+      new_speed = std::max(bbd->wanted_speed, old_speed - val.max_acc);
     }
     else {
       new_speed = std::min(bbd->wanted_speed, old_speed + val.max_acc);
@@ -1346,7 +1346,7 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa)
 
     /* finally constrain speed to max speed */
     new_speed = normalize_v3(new_vel);
-    mul_v3_fl(new_vel, MIN2(new_speed, val.max_speed));
+    mul_v3_fl(new_vel, std::min(new_speed, val.max_speed));
 
     /* get acceleration from difference of velocities */
     sub_v3_v3v3(acc, new_vel, pa->prev_state.vel);
diff --git a/source/blender/blenkernel/intern/collision.cc b/source/blender/blenkernel/intern/collision.cc
index 82859fcab72a5eb6e56cd2192685c2a3c53b6a17..6377fcd8bc314676df49914d4e2f4dea769a51f1 100644
--- a/source/blender/blenkernel/intern/collision.cc
+++ b/source/blender/blenkernel/intern/collision.cc
@@ -6,6 +6,8 @@
  * \ingroup bke
  */
 
+#include <algorithm>
+
 #include "MEM_guardedalloc.h"
 
 #include "DNA_cloth_types.h"
@@ -896,7 +898,7 @@ static int cloth_selfcollision_response_static(ClothModifierData *clmd,
       VECADDMUL(ib[2], collpair->normal, double(u3) * -impulse);
 
       if ((magrelVel < 0.1f * d * time_multiplier) && (d > ALMOST_ZERO)) {
-        repulse = MIN2(d / time_multiplier, 0.1f * d * time_multiplier - magrelVel);
+        repulse = std::min(d / time_multiplier, 0.1f * d * time_multiplier - magrelVel);
 
         if (impulse > ALMOST_ZERO) {
           repulse = min_ff(repulse, 5.0 * impulse);
@@ -1720,7 +1722,7 @@ int cloth_bvh_collision(
 
   BKE_collision_objects_free(collobjs);
 
-  return MIN2(ret, 1);
+  return std::min(ret, 1);
 }
 
 BLI_INLINE void max_v3_v3v3(float r[3], const float a[3], const float b[3])
diff --git a/source/blender/blenkernel/intern/effect.cc b/source/blender/blenkernel/intern/effect.cc
index 223877a410e8875656ec9cd0ac0e7d95c4d55048..9dede98ec28711755ac0cf4ffb202b7caf6cc524 100644
--- a/source/blender/blenkernel/intern/effect.cc
+++ b/source/blender/blenkernel/intern/effect.cc
@@ -6,10 +6,10 @@
  * \ingroup bke
  */
 
+#include <algorithm>
+#include <cmath>
 #include <cstdarg>
 #include <cstddef>
-
-#include <cmath>
 #include <cstdlib>
 
 #include "MEM_guardedalloc.h"
@@ -1075,8 +1075,8 @@ static void do_physical_effector(EffectorCache *eff,
       copy_v3_v3(force, point->vel);
       fac = normalize_v3(force) * point->vel_to_sec;
 
-      strength = MIN2(strength, 2.0f);
-      damp = MIN2(damp, 2.0f);
+      strength = std::min(strength, 2.0f);
+      damp = std::min(damp, 2.0f);
 
       mul_v3_fl(force, -efd->falloff * fac * (strength * fac + damp));
       break;
diff --git a/source/blender/blenkernel/intern/fluid.cc b/source/blender/blenkernel/intern/fluid.cc
index 8a32fa5d205a0b1a1798a8cb143c97b08e89443c..28913e7349c5bded6ce88f2ab092f5565131a814 100644
--- a/source/blender/blenkernel/intern/fluid.cc
+++ b/source/blender/blenkernel/intern/fluid.cc
@@ -442,7 +442,7 @@ static void manta_set_domain_from_mesh(FluidDomainSettings *fds,
   }
 
   /* Define grid resolutions from longest domain side. */
-  if (size[0] >= MAX2(size[1], size[2])) {
+  if (size[0] >= std::max(size[1], size[2])) {
     scale = res / size[0];
     fds->scale = size[0] / fabsf(ob->scale[0]);
     fds->base_res[0] = res;
@@ -793,8 +793,8 @@ static void bb_combineMaps(FluidObjectBB *output,
                                                       output->influence[index_out]);
             }
           }
-          output->distances[index_out] = MIN2(bb2->distances[index_in],
-                                              output->distances[index_out]);
+          output->distances[index_out] = std::min(bb2->distances[index_in],
+                                                  output->distances[index_out]);
           if (output->velocity && bb2->velocity) {
             /* Last sample replaces the velocity. */
             output->velocity[index_out * 3] = ADD_IF_LOWER(output->velocity[index_out * 3],
@@ -832,7 +832,7 @@ BLI_INLINE void apply_effector_fields(FluidEffectorSettings * /*fes*/,
 {
   /* Ensure that distance value is "joined" into the levelset. */
   if (dest_phi_in) {
-    dest_phi_in[index] = MIN2(src_distance_value, dest_phi_in[index]);
+    dest_phi_in[index] = std::min(src_distance_value, dest_phi_in[index]);
   }
 
   /* Accumulate effector object count (important once effector object overlap). */
@@ -914,15 +914,15 @@ static void update_velocities(FluidEffectorSettings *fes,
           velocity_map[index * 3 + 2] = hit_vel[2];
           break;
         case FLUID_EFFECTOR_GUIDE_MIN:
-          velocity_map[index * 3] = MIN2(abs_hit_vel[0], abs_vel[0]);
-          velocity_map[index * 3 + 1] = MIN2(abs_hit_vel[1], abs_vel[1]);
-          velocity_map[index * 3 + 2] = MIN2(abs_hit_vel[2], abs_vel[2]);
+          velocity_map[index * 3] = std::min(abs_hit_vel[0], abs_vel[0]);
+          velocity_map[index * 3 + 1] = std::min(abs_hit_vel[1], abs_vel[1]);
+          velocity_map[index * 3 + 2] = std::min(abs_hit_vel[2], abs_vel[2]);
           break;
         case FLUID_EFFECTOR_GUIDE_MAX:
         default:
-          velocity_map[index * 3] = MAX2(abs_hit_vel[0], abs_vel[0]);
-          velocity_map[index * 3 + 1] = MAX2(abs_hit_vel[1], abs_vel[1]);
-          velocity_map[index * 3 + 2] = MAX2(abs_hit_vel[2], abs_vel[2]);
+          velocity_map[index * 3] = std::max(abs_hit_vel[0], abs_vel[0]);
+          velocity_map[index * 3 + 1] = std::max(abs_hit_vel[1], abs_vel[1]);
+          velocity_map[index * 3 + 2] = std::max(abs_hit_vel[2], abs_vel[2]);
           break;
       }
     }
@@ -1792,7 +1792,7 @@ static void update_distances(int index,
   }
 
   /* Update global distance array but ensure that older entries are not overridden. */
-  distance_map[index] = MIN2(distance_map[index], min_dist);
+  distance_map[index] = std::min(distance_map[index], min_dist);
 
   /* Sanity check: Ensure that distances don't explode. */
   CLAMP(distance_map[index], -PHI_MAX, PHI_MAX);
@@ -1973,8 +1973,8 @@ static void sample_mesh(FluidFlowSettings *ffs,
       float convert_vel[3];
       copy_v3_v3(convert_vel, ffs->vel_coord);
       float time_mult = 1.0 / (25.0f * DT_DEFAULT);
-      float size_mult = MAX3(base_res[0], base_res[1], base_res[2]) /
-                        MAX3(global_size[0], global_size[1], global_size[2]);
+      float size_mult = std::max({base_res[0], base_res[1], base_res[2]}) /
+                        std::max({global_size[0], global_size[1], global_size[2]});
       mul_v3_v3fl(convert_vel, ffs->vel_coord, size_mult * time_mult);
 
       velocity_map[index * 3] += convert_vel[0];
@@ -1990,7 +1990,7 @@ static void sample_mesh(FluidFlowSettings *ffs,
   }
 
   /* Apply final influence value but also consider volume initialization factor. */
-  influence_map[index] = MAX2(volume_factor, emission_strength);
+  influence_map[index] = std::max(volume_factor, emission_strength);
 }
 
 struct EmitFromDMData {
@@ -2269,7 +2269,7 @@ static void adaptive_domain_adjust(
                                 y - fds->res_min[1],
                                 fds->res[1],
                                 z - fds->res_min[2]);
-        max_den = (fuel) ? MAX2(density[index], fuel[index]) : density[index];
+        max_den = (fuel) ? std::max(density[index], fuel[index]) : density[index];
 
         /* Check high resolution bounds if max density isn't already high enough. */
         if (max_den < fds->adapt_threshold && fds->flags & FLUID_DOMAIN_USE_NOISE && fds->fluid) {
@@ -2283,7 +2283,7 @@ static void adaptive_domain_adjust(
             for (j = 0; j < block_size; j++) {
               for (k = 0; k < block_size; k++) {
                 int big_index = manta_get_index(xx + i, wt_res[0], yy + j, wt_res[1], zz + k);
-                float den = (bigfuel) ? MAX2(bigdensity[big_index], bigfuel[big_index]) :
+                float den = (bigfuel) ? std::max(bigdensity[big_index], bigfuel[big_index]) :
                                         bigdensity[big_index];
                 if (den > max_den) {
                   max_den = den;
@@ -2433,7 +2433,7 @@ BLI_INLINE void apply_outflow_fields(int index,
   /* Set levelset value for liquid inflow.
    * Ensure that distance value is "joined" into the levelset. */
   if (phiout) {
-    phiout[index] = MIN2(distance_value, phiout[index]);
+    phiout[index] = std::min(distance_value, phiout[index]);
   }
 
   /* Set smoke outflow, i.e. reset cell to zero. */
@@ -2478,7 +2478,7 @@ BLI_INLINE void apply_inflow_fields(FluidFlowSettings *ffs,
   /* Set levelset value for liquid inflow.
    * Ensure that distance value is "joined" into the levelset. */
   if (phi_in) {
-    phi_in[index] = MIN2(distance_value, phi_in[index]);
+    phi_in[index] = std::min(distance_value, phi_in[index]);
   }
 
   /* Set emission value for smoke inflow.
@@ -2504,13 +2504,13 @@ BLI_INLINE void apply_inflow_fields(FluidFlowSettings *ffs,
   if (absolute_flow) {
     if (density && density_in) {
       if (ffs->type != FLUID_FLOW_TYPE_FIRE && dens_flow > density[index]) {
-        /* Use MAX2 to preserve values from other emitters at this cell. */
+        /* Use std::max to preserve values from other emitters at this cell. */
         density_in[index] = std::max(dens_flow, density_in[index]);
       }
     }
     if (fuel && fuel_in) {
       if (ffs->type != FLUID_FLOW_TYPE_SMOKE && fuel_flow && fuel_flow > fuel[index]) {
-        /* Use MAX2 to preserve values from other emitters at this cell. */
+        /* Use std::max to preserve values from other emitters at this cell. */
         fuel_in[index] = std::max(fuel_flow, fuel_in[index]);
       }
     }
@@ -3130,7 +3130,7 @@ static void update_effectors_task_cb(void *__restrict userdata,
       float voxel_center[3] = {0, 0, 0}, vel[3] = {0, 0, 0}, retvel[3] = {0, 0, 0};
       const uint index = manta_get_index(x, fds->res[0], y, fds->res[1], z);
 
-      if ((data->fuel && MAX2(data->density[index], data->fuel[index]) < FLT_EPSILON) ||
+      if ((data->fuel && std::max(data->density[index], data->fuel[index]) < FLT_EPSILON) ||
           (data->density && data->density[index] < FLT_EPSILON) ||
           (data->phi_obs_in && data->phi_obs_in[index] < 0.0f) ||
           data->flags[index] & 2) /* Manta-flow convention: `2 == FlagObstacle`. */
@@ -3276,7 +3276,7 @@ static Mesh *create_liquid_geometry(FluidDomainSettings *fds,
   sub_v3_v3v3(size, max, min);
 
   /* Biggest dimension will be used for up-scaling. */
-  float max_size = MAX3(size[0], size[1], size[2]);
+  float max_size = std::max({size[0], size[1], size[2]});
 
   float co_scale[3];
   co_scale[0] = max_size / ob->scale[0];
@@ -4379,8 +4379,8 @@ float BKE_fluid_get_velocity_at(Object *ob, float position[3], float velocity[3]
   if (fmd && (fmd->type & MOD_FLUID_TYPE_DOMAIN) && fmd->domain && fmd->domain->fluid) {
     FluidDomainSettings *fds = fmd->domain;
     float time_mult = 25.0f * DT_DEFAULT;
-    float size_mult = MAX3(fds->global_size[0], fds->global_size[1], fds->global_size[2]) /
-                      MAX3(fds->base_res[0], fds->base_res[1], fds->base_res[2]);
+    float size_mult = std::max({fds->global_size[0], fds->global_size[1], fds->global_size[2]}) /
+                      std::max({fds->base_res[0], fds->base_res[1], fds->base_res[2]});
     float vel_mag;
     float density = 0.0f, fuel = 0.0f;
     float pos[3];
diff --git a/source/blender/blenkernel/intern/gpencil_geom_legacy.cc b/source/blender/blenkernel/intern/gpencil_geom_legacy.cc
index 3a1d2a606c9672d48046ad78c22cdea33de6e53a..9468b8fe4e9086ee8321409ebe50535aa51295bd 100644
--- a/source/blender/blenkernel/intern/gpencil_geom_legacy.cc
+++ b/source/blender/blenkernel/intern/gpencil_geom_legacy.cc
@@ -6,6 +6,7 @@
  * \ingroup bke
  */
 
+#include <algorithm>
 #include <cmath>
 #include <cstddef>
 #include <cstdio>
@@ -1662,7 +1663,7 @@ float BKE_gpencil_stroke_segment_length(const bGPDstroke *gps,
     return 0.0f;
   }
 
-  int index = MAX2(start_index, 0) + 1;
+  int index = std::max(start_index, 0) + 1;
   int last_index = std::min(end_index, gps->totpoints - 1) + 1;
 
   float *last_pt = &gps->points[index - 1].x;
@@ -1804,7 +1805,7 @@ bool BKE_gpencil_stroke_close(bGPDstroke *gps)
   }
 
   /* Calc number of points required using the average distance. */
-  int tot_newpoints = MAX2(dist_close / dist_avg, 1);
+  int tot_newpoints = std::max<int>(dist_close / dist_avg, 1);
 
   /* Resize stroke array. */
   int old_tot = gps->totpoints;
@@ -2531,7 +2532,7 @@ static void gpencil_generate_edgeloops(Object *ob,
 
     /* Create Stroke. */
     bGPDstroke *gps_stroke = BKE_gpencil_stroke_add(
-        gpf_stroke, MAX2(stroke_mat_index, 0), array_len + 1, thickness * thickness, false);
+        gpf_stroke, std::max(stroke_mat_index, 0), array_len + 1, thickness * thickness, false);
 
     /* Create dvert data. */
     if (use_vgroups && !dverts.is_empty()) {
@@ -3710,7 +3711,7 @@ void BKE_gpencil_stroke_uniform_subdivide(bGPdata *gpd,
                    (float *)&sp_next->vertex_color,
                    0.5f);
     if (sp->dw && sp_next->dw) {
-      new_sp->totweight = MIN2(sp->totweight, sp_next->totweight);
+      new_sp->totweight = std::min(sp->totweight, sp_next->totweight);
       new_sp->dw = (MDeformWeight *)MEM_callocN(sizeof(MDeformWeight) * new_sp->totweight,
                                                 __func__);
       for (uint32_t i = 0; i < new_sp->totweight; ++i) {
diff --git a/source/blender/blenkernel/intern/gpencil_modifier_legacy.cc b/source/blender/blenkernel/intern/gpencil_modifier_legacy.cc
index ca37a21f631d5b00b46f95ad7ddccc5eaf7c9422..d3c31ec83ea754da8fc0066446f933fce4f614f7 100644
--- a/source/blender/blenkernel/intern/gpencil_modifier_legacy.cc
+++ b/source/blender/blenkernel/intern/gpencil_modifier_legacy.cc
@@ -6,6 +6,7 @@
  * \ingroup bke
  */
 
+#include <algorithm>
 #include <cstdio>
 
 #include "MEM_guardedalloc.h"
@@ -227,12 +228,13 @@ GpencilLineartLimitInfo BKE_gpencil_get_lineart_modifier_limits(const Object *ob
     if (md->type == eGpencilModifierType_Lineart) {
       LineartGpencilModifierData *lmd = (LineartGpencilModifierData *)md;
       if (is_first || (lmd->flags & LRT_GPENCIL_USE_CACHE)) {
-        info.min_level = MIN2(info.min_level, lmd->level_start);
-        info.max_level = MAX2(info.max_level,
-                              (lmd->use_multiple_levels ? lmd->level_end : lmd->level_start));
+        info.min_level = std::min<char>(info.min_level, lmd->level_start);
+        info.max_level = std::max<char>(
+            info.max_level, (lmd->use_multiple_levels ? lmd->level_end : lmd->level_start));
         info.edge_types |= lmd->edge_types;
-        info.shadow_selection = MAX2(lmd->shadow_selection, info.shadow_selection);
-        info.silhouette_selection = MAX2(lmd->silhouette_selection, info.silhouette_selection);
+        info.shadow_selection = std::max<char>(lmd->shadow_selection, info.shadow_selection);
+        info.silhouette_selection = std::max<char>(lmd->silhouette_selection,
+                                                   info.silhouette_selection);
         is_first = false;
       }
     }
diff --git a/source/blender/blenkernel/intern/idprop_utils.cc b/source/blender/blenkernel/intern/idprop_utils.cc
index 05a37e46570fb3964f27e5a61687a2eaea5eea61..c25e253d12318016e98f739546919119bdc3c1aa 100644
--- a/source/blender/blenkernel/intern/idprop_utils.cc
+++ b/source/blender/blenkernel/intern/idprop_utils.cc
@@ -6,6 +6,7 @@
  * \ingroup bke
  */
 
+#include <algorithm>
 #include <cstdio>
 #include <cstring>
 
@@ -96,7 +97,7 @@ static void idp_repr_fn_recursive(ReprState *state, const IDProperty *prop)
 
   switch (prop->type) {
     case IDP_STRING: {
-      STR_APPEND_STR_LEN_QUOTE(IDP_String(prop), uint(MAX2(0, prop->len - 1)));
+      STR_APPEND_STR_LEN_QUOTE(IDP_String(prop), uint(std::max(0, prop->len - 1)));
       break;
     }
     case IDP_INT: {
diff --git a/source/blender/blenkernel/intern/mask_evaluate.cc b/source/blender/blenkernel/intern/mask_evaluate.cc
index a7fedbe750472dfa09eab60a5b47fe8dcd45b954..28bfe9e841e0112eab5db3c3d1fe0b817b12a4a8 100644
--- a/source/blender/blenkernel/intern/mask_evaluate.cc
+++ b/source/blender/blenkernel/intern/mask_evaluate.cc
@@ -388,7 +388,7 @@ void BKE_mask_spline_feather_collapse_inner_loops(MaskSpline *spline,
   max_delta_x /= max[0] - min[0];
   max_delta_y /= max[1] - min[1];
 
-  max_delta = MAX2(max_delta_x, max_delta_y);
+  max_delta = std::max(max_delta_x, max_delta_y);
 
   buckets_per_side = min_ii(512, 0.9f / max_delta);
 
diff --git a/source/blender/blenkernel/intern/multires.cc b/source/blender/blenkernel/intern/multires.cc
index 0a70a5c1426422a313c3ad40a4eaf509d8ef62a7..4f112b8f8ca77410d191bae2cb30ea89640c4d8f 100644
--- a/source/blender/blenkernel/intern/multires.cc
+++ b/source/blender/blenkernel/intern/multires.cc
@@ -358,11 +358,11 @@ void multires_set_tot_level(Object *ob, MultiresModifierData *mmd, int lvl)
   mmd->totlvl = lvl;
 
   if (ob->mode != OB_MODE_SCULPT) {
-    mmd->lvl = CLAMPIS(MAX2(mmd->lvl, lvl), 0, mmd->totlvl);
+    mmd->lvl = CLAMPIS(std::max<char>(mmd->lvl, lvl), 0, mmd->totlvl);
   }
 
-  mmd->sculptlvl = CLAMPIS(MAX2(mmd->sculptlvl, lvl), 0, mmd->totlvl);
-  mmd->renderlvl = CLAMPIS(MAX2(mmd->renderlvl, lvl), 0, mmd->totlvl);
+  mmd->sculptlvl = CLAMPIS(std::max<char>(mmd->sculptlvl, lvl), 0, mmd->totlvl);
+  mmd->renderlvl = CLAMPIS(std::max<char>(mmd->renderlvl, lvl), 0, mmd->totlvl);
 }
 
 static void multires_ccg_mark_as_modified(SubdivCCG *subdiv_ccg, MultiresModifiedFlags flags)
diff --git a/source/blender/blenkernel/intern/particle.cc b/source/blender/blenkernel/intern/particle.cc
index 95dd3800627502e7230b06a17bc36cdb81f1ce90..7865e9f4fd0a850f43b2a871b95a9d7290d02903 100644
--- a/source/blender/blenkernel/intern/particle.cc
+++ b/source/blender/blenkernel/intern/particle.cc
@@ -9,6 +9,7 @@
 /* Allow using deprecated functionality for .blend file I/O. */
 #define DNA_DEPRECATED_ALLOW
 
+#include <algorithm>
 #include <cmath>
 #include <cstdlib>
 #include <cstring>
@@ -2718,7 +2719,7 @@ static bool psys_thread_context_init_path(ParticleThreadContext *ctx,
     totchild = int(float(totchild) * float(part->disp) / 100.0f);
   }
 
-  totparent = MIN2(totparent, totchild);
+  totparent = std::min(totparent, totchild);
 
   if (totchild == 0) {
     return false;
@@ -3356,7 +3357,7 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra, const bool use_re
     copy_v3_v3(rotmat[2], hairmat[0]);
 
     if (part->draw & PART_ABS_PATH_TIME) {
-      birthtime = MAX2(pind.birthtime, part->path_start);
+      birthtime = std::max(pind.birthtime, part->path_start);
       dietime = std::min(pind.dietime, part->path_end);
     }
     else {
diff --git a/source/blender/blenkernel/intern/particle_distribute.cc b/source/blender/blenkernel/intern/particle_distribute.cc
index abe5ad28cae1832a3591317a098970b4a6516a9b..2834d4f5246702ea442c516ff206a76adad6ae90 100644
--- a/source/blender/blenkernel/intern/particle_distribute.cc
+++ b/source/blender/blenkernel/intern/particle_distribute.cc
@@ -127,7 +127,7 @@ static void distribute_grid(Mesh *mesh, ParticleSystem *psys)
   size[(axis + 2) % 3] = int(ceil(delta[(axis + 2) % 3] / d));
 
   /* float errors grrr. */
-  size[(axis + 1) % 3] = MIN2(size[(axis + 1) % 3], res);
+  size[(axis + 1) % 3] = std::min(size[(axis + 1) % 3], res);
   size[(axis + 2) % 3] = std::min(size[(axis + 2) % 3], res);
 
   size[0] = std::max(size[0], 1);
@@ -1122,7 +1122,7 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx,
     maxweight /= totarea;
   }
   else {
-    float min = 1.0f / float(MIN2(totelem, totpart));
+    float min = 1.0f / float(std::min(totelem, totpart));
     for (i = 0; i < totelem; i++) {
       element_weight[i] = min;
     }
diff --git a/source/blender/blenkernel/intern/particle_system.cc b/source/blender/blenkernel/intern/particle_system.cc
index f690b9cd920d36c38c9d7e83ed85f2ed6e0072d3..e2f6dbfc93358ea9ac48e4b51e748965a444d44d 100644
--- a/source/blender/blenkernel/intern/particle_system.cc
+++ b/source/blender/blenkernel/intern/particle_system.cc
@@ -9,6 +9,7 @@
 
 #include <cstddef>
 
+#include <algorithm>
 #include <cmath>
 #include <cstdlib>
 #include <cstring>
@@ -232,7 +233,7 @@ static void realloc_particles(ParticleSimulationData *sim, int new_totpart)
     }
 
     if (psys->particles) {
-      totsaved = MIN2(psys->totpart, totpart);
+      totsaved = std::min(psys->totpart, totpart);
       /* Save old pars. */
       if (totsaved) {
         memcpy(newpars, psys->particles, totsaved * sizeof(ParticleData));
@@ -4404,7 +4405,8 @@ static void particles_fluid_step(ParticleSimulationData *sim,
           sub_v3_v3v3(size, max, min);
 
           /* Biggest dimension will be used for up-scaling. */
-          max_size = MAX3(size[0] / float(upres), size[1] / float(upres), size[2] / float(upres));
+          max_size = std::max(
+              {size[0] / float(upres), size[1] / float(upres), size[2] / float(upres)});
 
           /* Set particle position. */
           const float posParticle[3] = {posX, posY, posZ};
diff --git a/source/blender/blenkernel/intern/pointcache.cc b/source/blender/blenkernel/intern/pointcache.cc
index 7b6a234891c51d7e507981783eb79408f5912e98..abc9554b8d09ad44e1dc965fb80d8ce17e520284 100644
--- a/source/blender/blenkernel/intern/pointcache.cc
+++ b/source/blender/blenkernel/intern/pointcache.cc
@@ -6,6 +6,7 @@
  * \ingroup bke
  */
 
+#include <algorithm>
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
@@ -408,7 +409,7 @@ static void ptcache_particle_interpolate(int index,
     return;
   }
 
-  cfra = MIN2(cfra, pa->dietime);
+  cfra = std::min(cfra, pa->dietime);
   cfra1 = std::min(cfra1, pa->dietime);
   cfra2 = std::min(cfra2, pa->dietime);
 
@@ -442,7 +443,7 @@ static void ptcache_particle_interpolate(int index,
   }
 
   if (cfra > pa->time) {
-    cfra1 = MAX2(cfra1, pa->time);
+    cfra1 = std::max(cfra1, pa->time);
   }
 
   dfra = cfra2 - cfra1;
@@ -2194,7 +2195,7 @@ static int ptcache_read(PTCacheID *pid, int cfra)
 
       if (totpoint != pid_totpoint) {
         pid->error(pid->owner_id, pid->calldata, "Number of points in cache does not match mesh");
-        totpoint = MIN2(totpoint, pid_totpoint);
+        totpoint = std::min(totpoint, pid_totpoint);
       }
     }
 
@@ -2251,7 +2252,7 @@ static int ptcache_interpolate(PTCacheID *pid, float cfra, int cfra1, int cfra2)
 
       if (totpoint != pid_totpoint) {
         pid->error(pid->owner_id, pid->calldata, "Number of points in cache does not match mesh");
-        totpoint = MIN2(totpoint, pid_totpoint);
+        totpoint = std::min(totpoint, pid_totpoint);
       }
     }
 
@@ -3227,7 +3228,7 @@ void BKE_ptcache_bake(PTCacheBaker *baker)
         cache->flag |= PTCACHE_BAKING;
       }
       else {
-        endframe = MIN2(endframe, cache->endframe);
+        endframe = std::min(endframe, cache->endframe);
       }
 
       cache->flag &= ~PTCACHE_BAKED;
@@ -3267,13 +3268,13 @@ void BKE_ptcache_bake(PTCacheBaker *baker)
             BKE_ptcache_id_clear(pid, PTCACHE_CLEAR_ALL, 0);
           }
 
-          startframe = MIN2(startframe, cache->startframe);
+          startframe = std::min(startframe, cache->startframe);
 
           if (bake || render) {
             cache->flag |= PTCACHE_BAKING;
 
             if (bake) {
-              endframe = MAX2(endframe, cache->endframe);
+              endframe = std::max(endframe, cache->endframe);
             }
           }
 
diff --git a/source/blender/blenkernel/intern/rigidbody.cc b/source/blender/blenkernel/intern/rigidbody.cc
index 56aead3de75761ffdda89eb28ba3bafe66f6ccbc..2500f290ce6b3b143228de76d8a636e2de06036d 100644
--- a/source/blender/blenkernel/intern/rigidbody.cc
+++ b/source/blender/blenkernel/intern/rigidbody.cc
@@ -7,6 +7,7 @@
  * \brief Blender-side interface and methods for dealing with Rigid Body simulations
  */
 
+#include <algorithm>
 #include <cfloat>
 #include <climits>
 #include <cmath>
@@ -505,7 +506,7 @@ static rbCollisionShape *rigidbody_validate_sim_shape_helper(RigidBodyWorld *rbw
   }
   else if (rbo->shape == RB_SHAPE_SPHERE) {
     /* take radius to the largest dimension to try and encompass everything */
-    radius = MAX3(size[0], size[1], size[2]);
+    radius = std::max({size[0], size[1], size[2]});
   }
 
   /* create new shape */
@@ -531,7 +532,7 @@ static rbCollisionShape *rigidbody_validate_sim_shape_helper(RigidBodyWorld *rbw
 
     case RB_SHAPE_CONVEXH:
       /* try to embed collision margin */
-      has_volume = (MIN3(size[0], size[1], size[2]) > 0.0f);
+      has_volume = (std::min({size[0], size[1], size[2]}) > 0.0f);
 
       if (!(rbo->flag & RBO_FLAG_USE_MARGIN) && has_volume) {
         hull_margin = 0.04f;
@@ -636,7 +637,7 @@ void BKE_rigidbody_calc_volume(Object *ob, float *r_vol)
 
   if (ELEM(rbo->shape, RB_SHAPE_CAPSULE, RB_SHAPE_CYLINDER, RB_SHAPE_CONE)) {
     /* take radius as largest x/y dimension, and height as z-dimension */
-    radius = MAX2(size[0], size[1]) * 0.5f;
+    radius = std::max(size[0], size[1]) * 0.5f;
     height = size[2];
   }
   else if (rbo->shape == RB_SHAPE_SPHERE) {
@@ -1790,7 +1791,8 @@ static void rigidbody_update_sim_ob(Depsgraph *depsgraph, Object *ob, RigidBodyO
       /* compensate for embedded convex hull collision margin */
       if (!(rbo->flag & RBO_FLAG_USE_MARGIN) && rbo->shape == RB_SHAPE_CONVEXH) {
         RB_shape_set_margin(static_cast<rbCollisionShape *>(rbo->shared->physics_shape),
-                            RBO_GET_MARGIN(rbo) * MIN3(new_scale[0], new_scale[1], new_scale[2]));
+                            RBO_GET_MARGIN(rbo) *
+                                std::min({new_scale[0], new_scale[1], new_scale[2]}));
       }
     }
   }
@@ -2026,7 +2028,7 @@ static void rigidbody_update_kinematic_obj_substep(ListBase *substep_targets, fl
     /* compensate for embedded convex hull collision margin */
     if (!(rbo->flag & RBO_FLAG_USE_MARGIN) && rbo->shape == RB_SHAPE_CONVEXH) {
       RB_shape_set_margin(static_cast<rbCollisionShape *>(rbo->shared->physics_shape),
-                          RBO_GET_MARGIN(rbo) * MIN3(scale[0], scale[1], scale[2]));
+                          RBO_GET_MARGIN(rbo) * std::min({scale[0], scale[1], scale[2]}));
     }
   }
 }
diff --git a/source/blender/blenkernel/intern/scene.cc b/source/blender/blenkernel/intern/scene.cc
index 8d0f3898802c07cb4eb88b70fef3a62f13422e81..a994edb4c0142a5c5941b9b758ba247fa5f86cab 100644
--- a/source/blender/blenkernel/intern/scene.cc
+++ b/source/blender/blenkernel/intern/scene.cc
@@ -994,7 +994,7 @@ static bool seq_foreach_path_callback(Sequence *seq, void *user_data)
 
       if (bpath_data->flag & BKE_BPATH_FOREACH_PATH_SKIP_MULTIFILE) {
         /* only operate on one path */
-        len = MIN2(1u, len);
+        len = std::min(1u, len);
       }
 
       for (i = 0; i < len; i++, se++) {
diff --git a/source/blender/blenkernel/intern/vfont.cc b/source/blender/blenkernel/intern/vfont.cc
index 3ec770ca0ff83ae3c465f6873c1b7333f0f8ffa0..27639f1797a49a3113c090b52c580276ecfe4c87 100644
--- a/source/blender/blenkernel/intern/vfont.cc
+++ b/source/blender/blenkernel/intern/vfont.cc
@@ -6,6 +6,7 @@
  * \ingroup bke
  */
 
+#include <algorithm>
 #include <cmath>
 #include <cstdio>
 #include <cstdlib>
@@ -1131,7 +1132,7 @@ static bool vfont_to_curve(Object *ob,
         current_line_length += twidth;
       }
       else {
-        longest_line_length = MAX2(current_line_length, longest_line_length);
+        longest_line_length = std::max(current_line_length, longest_line_length);
         current_line_length = 0.0f;
       }
 
@@ -1190,7 +1191,7 @@ static bool vfont_to_curve(Object *ob,
   }
 
   current_line_length += xof + twidth - MARGIN_X_MIN;
-  longest_line_length = MAX2(current_line_length, longest_line_length);
+  longest_line_length = std::max(current_line_length, longest_line_length);
 
   cu->lines = 1;
   for (i = 0; i <= slen; i++) {
diff --git a/source/blender/blenlib/BLI_index_mask.hh b/source/blender/blenlib/BLI_index_mask.hh
index 9e132a23f836f93a2303f869a331dcd11bad8b4f..10efe6d3141c94c8b624980b35d6a51bacef4af0 100644
--- a/source/blender/blenlib/BLI_index_mask.hh
+++ b/source/blender/blenlib/BLI_index_mask.hh
@@ -142,8 +142,8 @@ using IndexMaskSegment = OffsetSpan<int64_t, int16_t>;
  *   various sources. Those generally need additional memory which is provided with by an
  *   #IndexMaskMemory.
  *
- *   Some of the `IndexMask::from_*` functions are have an `IndexMask universe` input. When
- *   provided, the function will only consider the indices in the "universe". The term comes from
+ *   Some of the `IndexMask::from_*` functions have an `IndexMask universe` input. When provided,
+ *   the function will only consider the indices in the "universe". The term comes from
  *   mathematics: https://en.wikipedia.org/wiki/Universe_(mathematics).
  *
  * Iteration:
@@ -472,7 +472,7 @@ inline void init_empty_mask(IndexMaskData &data)
   data.indices_num_ = 0;
   data.segments_num_ = 0;
   data.cumulative_segment_sizes_ = cumulative_sizes_for_empty_mask;
-  /* Intentionally leave some pointer uninitialized which must not be accessed on empty masks
+  /* Intentionally leave some pointers uninitialized which must not be accessed on empty masks
    * anyway. */
 }
 
diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h
index 25ed1e27fecad19436fe29355e83153a4b0416fa..6ba1db047b89e913a78ccddf3b723251efcf67f0 100644
--- a/source/blender/blenlib/BLI_utildefines.h
+++ b/source/blender/blenlib/BLI_utildefines.h
@@ -32,76 +32,9 @@ extern "C" {
 /** \name Min/Max Macros
  * \{ */
 
-/* useful for finding bad use of min/max */
-#if 0
-/* gcc only */
-#  define _TYPECHECK(a, b) ((void)(((typeof(a) *)0) == ((typeof(b) *)0)))
-#  define MIN2(x, y) (_TYPECHECK(x, y), (((x) < (y) ? (x) : (y))))
-#  define MAX2(x, y) (_TYPECHECK(x, y), (((x) > (y) ? (x) : (y))))
-#endif
-
-/* min/max */
-#if defined(__GNUC__) || defined(__clang__)
-
-#  define MIN2(a, b) \
-    __extension__({ \
-      typeof(a) a_ = (a); \
-      typeof(b) b_ = (b); \
-      ((a_) < (b_) ? (a_) : (b_)); \
-    })
-
-#  define MAX2(a, b) \
-    __extension__({ \
-      typeof(a) a_ = (a); \
-      typeof(b) b_ = (b); \
-      ((a_) > (b_) ? (a_) : (b_)); \
-    })
-
-#  define MIN3(a, b, c) \
-    __extension__({ \
-      typeof(a) a_ = (a); \
-      typeof(b) b_ = (b); \
-      typeof(c) c_ = (c); \
-      ((a_ < b_) ? ((a_ < c_) ? a_ : c_) : ((b_ < c_) ? b_ : c_)); \
-    })
-
-#  define MAX3(a, b, c) \
-    __extension__({ \
-      typeof(a) a_ = (a); \
-      typeof(b) b_ = (b); \
-      typeof(c) c_ = (c); \
-      ((a_ > b_) ? ((a_ > c_) ? a_ : c_) : ((b_ > c_) ? b_ : c_)); \
-    })
-
-#  define MIN4(a, b, c, d) \
-    __extension__({ \
-      typeof(a) a_ = (a); \
-      typeof(b) b_ = (b); \
-      typeof(c) c_ = (c); \
-      typeof(d) d_ = (d); \
-      ((a_ < b_) ? ((a_ < c_) ? ((a_ < d_) ? a_ : d_) : ((c_ < d_) ? c_ : d_)) : \
-                   ((b_ < c_) ? ((b_ < d_) ? b_ : d_) : ((c_ < d_) ? c_ : d_))); \
-    })
-
-#  define MAX4(a, b, c, d) \
-    __extension__({ \
-      typeof(a) a_ = (a); \
-      typeof(b) b_ = (b); \
-      typeof(c) c_ = (c); \
-      typeof(d) d_ = (d); \
-      ((a_ > b_) ? ((a_ > c_) ? ((a_ > d_) ? a_ : d_) : ((c_ > d_) ? c_ : d_)) : \
-                   ((b_ > c_) ? ((b_ > d_) ? b_ : d_) : ((c_ > d_) ? c_ : d_))); \
-    })
-
-#else
+#ifndef __cplusplus
 #  define MIN2(a, b) ((a) < (b) ? (a) : (b))
 #  define MAX2(a, b) ((a) > (b) ? (a) : (b))
-
-#  define MIN3(a, b, c) (MIN2(MIN2((a), (b)), (c)))
-#  define MIN4(a, b, c, d) (MIN2(MIN2((a), (b)), MIN2((c), (d))))
-
-#  define MAX3(a, b, c) (MAX2(MAX2((a), (b)), (c)))
-#  define MAX4(a, b, c, d) (MAX2(MAX2((a), (b)), MAX2((c), (d))))
 #endif
 
 #define INIT_MINMAX(min, max) \
diff --git a/source/blender/blenlib/intern/array_store.cc b/source/blender/blenlib/intern/array_store.cc
index c9fb44dad879d4b8e3aaf747186b9d8c541a296f..9a1c02ddc768404d272bc1c42efd33504a412868 100644
--- a/source/blender/blenlib/intern/array_store.cc
+++ b/source/blender/blenlib/intern/array_store.cc
@@ -87,6 +87,7 @@
  * Otherwise new chunks are created.
  */
 
+#include <algorithm>
 #include <cstdlib>
 #include <cstring>
 
@@ -158,11 +159,11 @@ struct BChunkList;
 #  define BCHUNK_HASH_TABLE_ACCUMULATE_STEPS_32BITS 4
 #  define BCHUNK_HASH_TABLE_ACCUMULATE_STEPS_16BITS 5
 /**
- * Singe bytes (or boolean) arrays need a higher number of steps
+ * Single bytes (or boolean) arrays need a higher number of steps
  * because the resulting values are not unique enough to result in evenly distributed values.
  * Use more accumulation when the size of the structs is small, see: #105046.
  *
- * With 6 -> 22, one byte each - means an array of booleans can be combine into 22 bits
+ * With 6 -> 22, one byte each - means an array of booleans can be combined into 22 bits
  * representing 4,194,303 different combinations.
  */
 #  define BCHUNK_HASH_TABLE_ACCUMULATE_STEPS_8BITS 6
@@ -479,7 +480,7 @@ static void bchunk_list_ensure_min_size_last(const BArrayInfo *info,
     BChunk *chunk_curr = cref->link;
     BChunk *chunk_prev = cref->prev->link;
 
-    if (MIN2(chunk_prev->data_len, chunk_curr->data_len) < info->chunk_byte_size_min) {
+    if (std::min(chunk_prev->data_len, chunk_curr->data_len) < info->chunk_byte_size_min) {
       const size_t data_merge_len = chunk_prev->data_len + chunk_curr->data_len;
       /* We could pass, but no need. */
       if (data_merge_len <= info->chunk_byte_size_max) {
@@ -632,7 +633,7 @@ static void bchunk_list_append_data(const BArrayInfo *info,
     BChunkRef *cref = static_cast<BChunkRef *>(chunk_list->chunk_refs.last);
     BChunk *chunk_prev = cref->link;
 
-    if (MIN2(chunk_prev->data_len, data_len) < info->chunk_byte_size_min) {
+    if (std::min(chunk_prev->data_len, data_len) < info->chunk_byte_size_min) {
       const size_t data_merge_len = chunk_prev->data_len + data_len;
       /* Re-allocate for single user. */
       if (cref->link->users == 1) {
@@ -1004,7 +1005,7 @@ static hash_key key_from_chunk_ref(const BArrayInfo *info, const BChunkRef *cref
 {
   hash_key key;
   BChunk *chunk = cref->link;
-  const size_t data_hash_len = MIN2(chunk->data_len, BCHUNK_HASH_LEN * info->chunk_stride);
+  const size_t data_hash_len = std::min(chunk->data_len, BCHUNK_HASH_LEN * info->chunk_stride);
 
 #  ifdef USE_HASH_TABLE_KEY_CACHE
   key = chunk->key;
@@ -1039,7 +1040,7 @@ static const BChunkRef *table_lookup(const BArrayInfo *info,
   const size_t data_hash_len = BCHUNK_HASH_LEN * info->chunk_stride; /* TODO: cache. */
 
   const size_t size_left = data_len - offset;
-  const hash_key key = hash_data(&data[offset], MIN2(data_hash_len, size_left));
+  const hash_key key = hash_data(&data[offset], std::min(data_hash_len, size_left));
   const uint key_index = (uint)(key % (hash_key)table_len);
   for (BTableRef *tref = table[key_index]; tref; tref = tref->next) {
     const BChunkRef *cref = tref->cref;
@@ -1501,7 +1502,7 @@ BArrayStore *BLI_array_store_create(uint stride, uint chunk_count)
 
   bs->info.chunk_byte_size = chunk_count * stride;
 #ifdef USE_MERGE_CHUNKS
-  bs->info.chunk_byte_size_min = MAX2(1u, chunk_count / BCHUNK_SIZE_MIN_DIV) * stride;
+  bs->info.chunk_byte_size_min = std::max(1u, chunk_count / BCHUNK_SIZE_MIN_DIV) * stride;
   bs->info.chunk_byte_size_max = (chunk_count * BCHUNK_SIZE_MAX_MUL) * stride;
 #endif
 
@@ -1531,7 +1532,7 @@ BArrayStore *BLI_array_store_create(uint stride, uint chunk_count)
 
   bs->info.accum_read_ahead_bytes = bs->info.accum_read_ahead_len * stride;
 #else
-  bs->info.accum_read_ahead_bytes = MIN2((size_t)BCHUNK_HASH_LEN, chunk_count) * stride;
+  bs->info.accum_read_ahead_bytes = std::min((size_t)BCHUNK_HASH_LEN, chunk_count) * stride;
 #endif
 
   bs->memory.chunk_list = BLI_mempool_create(sizeof(BChunkList), 0, 512, BLI_MEMPOOL_NOP);
diff --git a/source/blender/blenlib/intern/fileops_c.cc b/source/blender/blenlib/intern/fileops_c.cc
index 0af70d107acef60a6578f25072457e9a0c4491cb..1d0b5e45a63a2133fa7ddc308417ff5c21a6288d 100644
--- a/source/blender/blenlib/intern/fileops_c.cc
+++ b/source/blender/blenlib/intern/fileops_c.cc
@@ -6,6 +6,7 @@
  * \ingroup bli
  */
 
+#include <algorithm>
 #include <cstdlib> /* malloc */
 #include <cstring>
 
@@ -106,7 +107,7 @@ int64_t BLI_read(int fd, void *buf, size_t nbytes)
                                buf,
 #ifdef WIN32
                                /* Read must not exceed INT_MAX on WIN32, clamp. */
-                               MIN2(nbytes, INT_MAX)
+                               std::min<size_t>(nbytes, INT_MAX)
 #else
                                nbytes
 #endif
diff --git a/source/blender/blenlib/intern/math_base_safe_inline.c b/source/blender/blenlib/intern/math_base_safe_inline.c
index 652281eb66a5c69ec5b58b5f22b2ef086e0e64de..aba423e9da387cd8bd1dc7a987f7ad46fe7cf8b3 100644
--- a/source/blender/blenlib/intern/math_base_safe_inline.c
+++ b/source/blender/blenlib/intern/math_base_safe_inline.c
@@ -37,7 +37,7 @@ MINLINE float safe_logf(float a, float base)
 
 MINLINE float safe_sqrtf(float a)
 {
-  return sqrtf(MAX2(a, 0.0f));
+  return sqrtf(max_ff(a, 0.0f));
 }
 
 MINLINE float safe_inverse_sqrtf(float a)
diff --git a/source/blender/blenlib/intern/path_util.cc b/source/blender/blenlib/intern/path_util.cc
index 1fff28dc7652cbe419a61e7b6ea5cc8cdcf0e90b..0a91702897f8b5120b5595456714883c242fc3ee 100644
--- a/source/blender/blenlib/intern/path_util.cc
+++ b/source/blender/blenlib/intern/path_util.cc
@@ -104,7 +104,7 @@ int BLI_path_sequence_decode(const char *path,
         BLI_strncpy(tail, &path[nume + 1], tail_maxncpy);
       }
       if (head) {
-        BLI_strncpy(head, path, MIN2(head_maxncpy, nums + 1));
+        BLI_strncpy(head, path, std::min<size_t>(head_maxncpy, nums + 1));
       }
       if (r_digits_len) {
         *r_digits_len = nume - nums + 1;
@@ -119,7 +119,7 @@ int BLI_path_sequence_decode(const char *path,
   if (head) {
     /* Name_end points to last character of head,
      * make it +1 so null-terminator is nicely placed. */
-    BLI_strncpy(head, path, MIN2(head_maxncpy, name_end + 1));
+    BLI_strncpy(head, path, std::min<size_t>(head_maxncpy, name_end + 1));
   }
   if (r_digits_len) {
     *r_digits_len = 0;
diff --git a/source/blender/blenlib/intern/string_utf8.cc b/source/blender/blenlib/intern/string_utf8.cc
index 6721469b5ec4e72575e4970c5e73550e951aa331..611af9de89ba6d09dffced95257cbb68746fc2fa 100644
--- a/source/blender/blenlib/intern/string_utf8.cc
+++ b/source/blender/blenlib/intern/string_utf8.cc
@@ -10,6 +10,7 @@
  * \ingroup bli
  */
 
+#include <algorithm>
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
@@ -1069,7 +1070,7 @@ int BLI_str_utf8_offset_from_index(const char *str, const size_t str_len, const
 int BLI_str_utf8_offset_to_column(const char *str, const size_t str_len, const int offset_target)
 {
   BLI_assert(offset_target >= 0);
-  const size_t offset_target_clamp = MIN2(size_t(offset_target), str_len);
+  const size_t offset_target_clamp = std::min(size_t(offset_target), str_len);
   size_t offset = 0;
   int column = 0;
   while (offset < offset_target_clamp) {
@@ -1101,7 +1102,7 @@ int BLI_str_utf8_offset_to_column_with_tabs(const char *str,
                                             const int tab_width)
 {
   BLI_assert(offset_target >= 0);
-  const size_t offset_target_clamp = MIN2(size_t(offset_target), str_len);
+  const size_t offset_target_clamp = std::min(size_t(offset_target), str_len);
   size_t offset = 0;
   int column = 0;
   while (offset < offset_target_clamp) {
diff --git a/source/blender/blenlib/tests/BLI_string_test.cc b/source/blender/blenlib/tests/BLI_string_test.cc
index a9b5f32a8f3565d0b0f61e5bfb5db768c108c9bf..ed7a22c3de3f484288d4feaa980cc061d5d56e48 100644
--- a/source/blender/blenlib/tests/BLI_string_test.cc
+++ b/source/blender/blenlib/tests/BLI_string_test.cc
@@ -53,7 +53,7 @@ TEST(string, StrCopyUTF8_ASCII_Truncate)
     char dst[sizeof(src)]; \
     memset(dst, 0xff, sizeof(dst)); \
     BLI_strncpy_utf8(dst, src, maxncpy); \
-    int len_expect = MIN2(sizeof(src), maxncpy) - 1; \
+    int len_expect = std::min<int>(sizeof(src), maxncpy) - 1; \
     src[len_expect] = '\0'; /* To be able to use `EXPECT_STREQ`. */ \
     EXPECT_EQ(strlen(dst), len_expect); \
     EXPECT_STREQ(dst, src); \
diff --git a/source/blender/blenloader/intern/readfile.cc b/source/blender/blenloader/intern/readfile.cc
index bdd942d06671a14478a44a92e30f9d50c250fe61..3b317b4fdbd535ea6dba7d3d981ffa26dcc665b6 100644
--- a/source/blender/blenloader/intern/readfile.cc
+++ b/source/blender/blenloader/intern/readfile.cc
@@ -698,7 +698,7 @@ static BHeadN *get_bhead(FileData *fd)
             bh8_from_bh4(&bhead, &bhead4);
           }
           else {
-            /* MIN2 is only to quiet '-Warray-bounds' compiler warning. */
+            /* std::min is only to quiet '-Warray-bounds' compiler warning. */
             BLI_assert(sizeof(bhead) == sizeof(bhead4));
             memcpy(&bhead, &bhead4, std::min(sizeof(bhead), sizeof(bhead4)));
           }
@@ -721,7 +721,7 @@ static BHeadN *get_bhead(FileData *fd)
             bh4_from_bh8(&bhead, &bhead8, (fd->flags & FD_FLAGS_SWITCH_ENDIAN) != 0);
           }
           else {
-            /* MIN2 is only to quiet `-Warray-bounds` compiler warning. */
+            /* std::min is only to quiet `-Warray-bounds` compiler warning. */
             BLI_assert(sizeof(bhead) == sizeof(bhead8));
             memcpy(&bhead, &bhead8, std::min(sizeof(bhead), sizeof(bhead8)));
           }
diff --git a/source/blender/blenloader/intern/versioning_280.cc b/source/blender/blenloader/intern/versioning_280.cc
index 31b9c08dbec7371f94d34a0b84c048648fbc971f..19d36e0af8eacb133443ef45768aa62f1791af23 100644
--- a/source/blender/blenloader/intern/versioning_280.cc
+++ b/source/blender/blenloader/intern/versioning_280.cc
@@ -9,6 +9,7 @@
 /* allow readfile to use deprecated functionality */
 #define DNA_DEPRECATED_ALLOW
 
+#include <algorithm>
 #include <cfloat>
 #include <cstring>
 
@@ -3312,8 +3313,8 @@ void blo_do_versions_280(FileData *fd, Library * /*lib*/, Main *bmain)
       /* Calculate window width/height from screen vertices */
       int win_width = 0, win_height = 0;
       LISTBASE_FOREACH (ScrVert *, vert, &screen->vertbase) {
-        win_width = MAX2(win_width, vert->vec.x);
-        win_height = MAX2(win_height, vert->vec.y);
+        win_width = std::max<int>(win_width, vert->vec.x);
+        win_height = std::max<int>(win_height, vert->vec.y);
       }
 
       for (ScrArea *area = static_cast<ScrArea *>(screen->areabase.first), *area_next; area;
diff --git a/source/blender/blenloader/intern/versioning_290.cc b/source/blender/blenloader/intern/versioning_290.cc
index c845bd22193a310646784e6d9b6d46997ce449ee..03d07c483e8a15a12e7a2ae329cdaf08c8608108 100644
--- a/source/blender/blenloader/intern/versioning_290.cc
+++ b/source/blender/blenloader/intern/versioning_290.cc
@@ -8,6 +8,8 @@
 /* allow readfile to use deprecated functionality */
 #define DNA_DEPRECATED_ALLOW
 
+#include <algorithm>
+
 #include "BLI_listbase.h"
 #include "BLI_math_matrix.h"
 #include "BLI_math_rotation.h"
@@ -227,8 +229,8 @@ static void seq_convert_transform_crop(const Scene *scene,
     old_image_center_y = image_size_y / 2 - c->bottom + t->yofs;
 
     /* Preserve original image size. */
-    t->scale_x = t->scale_y = MAX2(float(image_size_x) / float(scene->r.xsch),
-                                   float(image_size_y) / float(scene->r.ysch));
+    t->scale_x = t->scale_y = std::max(float(image_size_x) / float(scene->r.xsch),
+                                       float(image_size_y) / float(scene->r.ysch));
 
     /* Convert crop. */
     if ((seq->flag & use_crop_flag) != 0) {
@@ -311,8 +313,8 @@ static void seq_convert_transform_crop_2(const Scene *scene,
   }
 
   /* Calculate scale factor, so image fits in preview area with original aspect ratio. */
-  const float scale_to_fit_factor = MIN2(float(scene->r.xsch) / float(image_size_x),
-                                         float(scene->r.ysch) / float(image_size_y));
+  const float scale_to_fit_factor = std::min(float(scene->r.xsch) / float(image_size_x),
+                                             float(scene->r.ysch) / float(image_size_y));
   t->scale_x *= scale_to_fit_factor;
   t->scale_y *= scale_to_fit_factor;
   c->top /= scale_to_fit_factor;
diff --git a/source/blender/blenloader/intern/versioning_legacy.cc b/source/blender/blenloader/intern/versioning_legacy.cc
index b477c676a1128d9d6bc6f9c479db608e565bc261..bb2269be4a89e39ec52839046ecc0de05e735d5a 100644
--- a/source/blender/blenloader/intern/versioning_legacy.cc
+++ b/source/blender/blenloader/intern/versioning_legacy.cc
@@ -6,6 +6,7 @@
  * \ingroup blenloader
  */
 
+#include <algorithm>
 #include <climits>
 
 #ifndef WIN32
@@ -1323,8 +1324,8 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain)
           SubsurfModifierData *smd = (SubsurfModifierData *)BKE_modifier_new(
               eModifierType_Subsurf);
 
-          smd->levels = MAX2(1, mesh->subdiv);
-          smd->renderLevels = MAX2(1, mesh->subdivr);
+          smd->levels = std::max<short>(1, mesh->subdiv);
+          smd->renderLevels = std::max<short>(1, mesh->subdivr);
           smd->subdivType = mesh->subsurftype;
 
           smd->modifier.mode = 0;
diff --git a/source/blender/compositor/intern/COM_ExecutionGroup.cc b/source/blender/compositor/intern/COM_ExecutionGroup.cc
index f4b7ebb0f6a92912a5f2749223b9a191d0a3d1a4..12ad6a0be5735c0a18ce25a330c75033539bd55f 100644
--- a/source/blender/compositor/intern/COM_ExecutionGroup.cc
+++ b/source/blender/compositor/intern/COM_ExecutionGroup.cc
@@ -438,8 +438,8 @@ inline void ExecutionGroup::determine_chunk_rect(rcti *r_rect,
   else {
     const uint minx = x_chunk * chunk_size_ + viewer_border_.xmin;
     const uint miny = y_chunk * chunk_size_ + viewer_border_.ymin;
-    const uint width = MIN2(uint(viewer_border_.xmax), width_);
-    const uint height = MIN2(uint(viewer_border_.ymax), height_);
+    const uint width = std::min(uint(viewer_border_.xmax), width_);
+    const uint height = std::min(uint(viewer_border_.ymax), height_);
     BLI_rcti_init(r_rect,
                   std::min(minx, width_),
                   std::min(minx + chunk_size_, width),
diff --git a/source/blender/compositor/intern/COM_MemoryBuffer.cc b/source/blender/compositor/intern/COM_MemoryBuffer.cc
index 2665b314bbf85f1571983b2008cdeebd2cd73c17..db6940f062a62a37583f07881f5ecc7c84ae91df 100644
--- a/source/blender/compositor/intern/COM_MemoryBuffer.cc
+++ b/source/blender/compositor/intern/COM_MemoryBuffer.cc
@@ -407,8 +407,8 @@ void MemoryBuffer::fill(const rcti &area,
 void MemoryBuffer::fill_from(const MemoryBuffer &src)
 {
   rcti overlap;
-  overlap.xmin = MAX2(rect_.xmin, src.rect_.xmin);
-  overlap.xmax = MIN2(rect_.xmax, src.rect_.xmax);
+  overlap.xmin = std::max(rect_.xmin, src.rect_.xmin);
+  overlap.xmax = std::min(rect_.xmax, src.rect_.xmax);
   overlap.ymin = std::max(rect_.ymin, src.rect_.ymin);
   overlap.ymax = std::min(rect_.ymax, src.rect_.ymax);
   copy_from(&src, overlap);
diff --git a/source/blender/compositor/operations/COM_BokehBlurOperation.cc b/source/blender/compositor/operations/COM_BokehBlurOperation.cc
index e07743ec1b3afea497ee6b7b5f3f57bf2d8ad706..e4a2bb40353ac264298aa7276291c40c4436739e 100644
--- a/source/blender/compositor/operations/COM_BokehBlurOperation.cc
+++ b/source/blender/compositor/operations/COM_BokehBlurOperation.cc
@@ -106,8 +106,8 @@ void BokehBlurOperation::execute_pixel(float output[4], int x, int y, void *data
     int maxx = x + pixel_size;
     miny = std::max(miny, input_rect.ymin);
     minx = std::max(minx, input_rect.xmin);
-    maxy = MIN2(maxy, input_rect.ymax);
-    maxx = MIN2(maxx, input_rect.xmax);
+    maxy = std::min(maxy, input_rect.ymax);
+    maxx = std::min(maxx, input_rect.xmax);
 
     int step = get_step();
     int offsetadd = get_offset_add() * COM_DATA_TYPE_COLOR_CHANNELS;
@@ -340,9 +340,9 @@ void BokehBlurOperation::update_memory_buffer_partial(MemoryBuffer *output,
       multiplier_accum[3] = 1.0f;
     }
     const int miny = std::max(y - pixel_size, image_rect.ymin);
-    const int maxy = MIN2(y + pixel_size, image_rect.ymax);
+    const int maxy = std::min(y + pixel_size, image_rect.ymax);
     const int minx = std::max(x - pixel_size, image_rect.xmin);
-    const int maxx = MIN2(x + pixel_size, image_rect.xmax);
+    const int maxx = std::min(x + pixel_size, image_rect.xmax);
     const int step = get_step();
     const int elem_stride = image_input->elem_stride * step;
     const int row_stride = image_input->row_stride * step;
diff --git a/source/blender/compositor/operations/COM_BoxMaskOperation.cc b/source/blender/compositor/operations/COM_BoxMaskOperation.cc
index d6f873bd7dc4394ce1cb187532364e8d3c08166e..55f68fefe273bb79581ce223d256576fc66b0d52 100644
--- a/source/blender/compositor/operations/COM_BoxMaskOperation.cc
+++ b/source/blender/compositor/operations/COM_BoxMaskOperation.cc
@@ -34,8 +34,8 @@ void BoxMaskOperation::execute_pixel_sampled(float output[4],
   float input_mask[4];
   float input_value[4];
 
-  float rx = x / MAX2(this->get_width() - 1.0f, FLT_EPSILON);
-  float ry = y / MAX2(this->get_height() - 1.0f, FLT_EPSILON);
+  float rx = x / std::max(this->get_width() - 1.0f, FLT_EPSILON);
+  float ry = y / std::max(this->get_height() - 1.0f, FLT_EPSILON);
 
   const float dy = (ry - data_->y) / aspect_ratio_;
   const float dx = rx - data_->x;
@@ -130,8 +130,8 @@ void BoxMaskOperation::apply_mask(MemoryBuffer *output,
                                   Span<MemoryBuffer *> inputs,
                                   MaskFunc mask_func)
 {
-  const float op_last_x = MAX2(this->get_width() - 1.0f, FLT_EPSILON);
-  const float op_last_y = MAX2(this->get_height() - 1.0f, FLT_EPSILON);
+  const float op_last_x = std::max(this->get_width() - 1.0f, FLT_EPSILON);
+  const float op_last_y = std::max(this->get_height() - 1.0f, FLT_EPSILON);
   const float half_w = data_->width / 2.0f + FLT_EPSILON;
   const float half_h = data_->height / 2.0f + FLT_EPSILON;
   for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
diff --git a/source/blender/compositor/operations/COM_ChannelMatteOperation.cc b/source/blender/compositor/operations/COM_ChannelMatteOperation.cc
index e6d100ffb56fa0f8a8869adfb9b588d9abc985c8..eb256c4d4ea78f3d24332a6f15fb916997576a97 100644
--- a/source/blender/compositor/operations/COM_ChannelMatteOperation.cc
+++ b/source/blender/compositor/operations/COM_ChannelMatteOperation.cc
@@ -115,7 +115,7 @@ void ChannelMatteOperation::update_memory_buffer_partial(MemoryBuffer *output,
     const float *color = it.in(0);
 
     /* Matte operation. */
-    float alpha = color[ids_[0]] - MAX2(color[ids_[1]], color[ids_[2]]);
+    float alpha = color[ids_[0]] - std::max(color[ids_[1]], color[ids_[2]]);
 
     /* Flip because 0.0 is transparent, not 1.0. */
     alpha = 1.0f - alpha;
@@ -136,7 +136,7 @@ void ChannelMatteOperation::update_memory_buffer_partial(MemoryBuffer *output,
      */
 
     /* Don't make something that was more transparent less transparent. */
-    *it.out = MIN2(alpha, color[3]);
+    *it.out = std::min(alpha, color[3]);
   }
 }
 
diff --git a/source/blender/compositor/operations/COM_ChannelMatteOperation.h b/source/blender/compositor/operations/COM_ChannelMatteOperation.h
index 6c0f5e89d3dea83ec79c349e62a524a0f3eb704d..1274004f3e8b8e71a1124164c1a8bedfefb4a070 100644
--- a/source/blender/compositor/operations/COM_ChannelMatteOperation.h
+++ b/source/blender/compositor/operations/COM_ChannelMatteOperation.h
@@ -27,12 +27,12 @@ class ChannelMatteOperation : public MultiThreadedOperation {
 
   /**
    * ids to use for the operations (max and simple)
-   * alpha = in[ids[0]] - MAX2(in[ids[1]], in[ids[2]])
+   * alpha = in[ids[0]] - std::max(in[ids[1]], in[ids[2]])
    * the simple operation is using:
    * alpha = in[ids[0]] - in[ids[1]]
    * but to use the same formula and operation for both we do:
    * ids[2] = ids[1]
-   * alpha = in[ids[0]] - MAX2(in[ids[1]], in[ids[2]])
+   * alpha = in[ids[0]] - std::max(in[ids[1]], in[ids[2]])
    */
   int ids_[3];
 
diff --git a/source/blender/compositor/operations/COM_ColorBalanceASCCDLOperation.cc b/source/blender/compositor/operations/COM_ColorBalanceASCCDLOperation.cc
index 7cfd9f4f4d864fff906ca40ab4bcfd699a20b46e..8968b009ce09e0d6102edd8f3375e8bff76313d2 100644
--- a/source/blender/compositor/operations/COM_ColorBalanceASCCDLOperation.cc
+++ b/source/blender/compositor/operations/COM_ColorBalanceASCCDLOperation.cc
@@ -47,7 +47,7 @@ void ColorBalanceASCCDLOperation::execute_pixel_sampled(float output[4],
   input_color_operation_->read_sampled(input_color, x, y, sampler);
 
   float fac = value[0];
-  fac = MIN2(1.0f, fac);
+  fac = std::min(1.0f, fac);
   const float mfac = 1.0f - fac;
 
   output[0] = mfac * input_color[0] +
@@ -64,7 +64,7 @@ void ColorBalanceASCCDLOperation::update_memory_buffer_row(PixelCursor &p)
   for (; p.out < p.row_end; p.next()) {
     const float *in_factor = p.ins[0];
     const float *in_color = p.ins[1];
-    const float fac = MIN2(1.0f, in_factor[0]);
+    const float fac = std::min(1.0f, in_factor[0]);
     const float fac_m = 1.0f - fac;
     p.out[0] = fac_m * in_color[0] +
                fac * colorbalance_cdl(in_color[0], offset_[0], power_[0], slope_[0]);
diff --git a/source/blender/compositor/operations/COM_ColorBalanceLGGOperation.cc b/source/blender/compositor/operations/COM_ColorBalanceLGGOperation.cc
index 29ffbff7195771d7a113790f426a6483be18a4d6..9b0e4466bba1089f98ed64884c6c1795cde6dfa3 100644
--- a/source/blender/compositor/operations/COM_ColorBalanceLGGOperation.cc
+++ b/source/blender/compositor/operations/COM_ColorBalanceLGGOperation.cc
@@ -71,7 +71,7 @@ void ColorBalanceLGGOperation::update_memory_buffer_row(PixelCursor &p)
   for (; p.out < p.row_end; p.next()) {
     const float *in_factor = p.ins[0];
     const float *in_color = p.ins[1];
-    const float fac = MIN2(1.0f, in_factor[0]);
+    const float fac = std::min(1.0f, in_factor[0]);
     const float fac_m = 1.0f - fac;
     p.out[0] = fac_m * in_color[0] +
                fac * colorbalance_lgg(in_color[0], lift_[0], gamma_inv_[0], gain_[0]);
diff --git a/source/blender/compositor/operations/COM_ColorCorrectionOperation.cc b/source/blender/compositor/operations/COM_ColorCorrectionOperation.cc
index 2520277729d997f5423ecfce645d325c9f7bea21..08b350c9d6c0eda015dbcfad4ffc147b208cdc5c 100644
--- a/source/blender/compositor/operations/COM_ColorCorrectionOperation.cc
+++ b/source/blender/compositor/operations/COM_ColorCorrectionOperation.cc
@@ -54,7 +54,7 @@ void ColorCorrectionOperation::execute_pixel_sampled(float output[4],
   float r, g, b;
 
   float value = input_mask[0];
-  value = MIN2(1.0f, value);
+  value = std::min(1.0f, value);
   const float mvalue = 1.0f - value;
 
   float level_shadows = 0.0;
@@ -204,7 +204,7 @@ void ColorCorrectionOperation::update_memory_buffer_row(PixelCursor &p)
     b = color_correct_powf_safe(b * gain + lift, inv_gamma, b);
 
     /* Mix with mask. */
-    const float value = MIN2(1.0f, in_mask[0]);
+    const float value = std::min(1.0f, in_mask[0]);
     const float value_ = 1.0f - value;
     r = value_ * in_color[0] + value * r;
     g = value_ * in_color[1] + value * g;
diff --git a/source/blender/compositor/operations/COM_ConvolutionEdgeFilterOperation.cc b/source/blender/compositor/operations/COM_ConvolutionEdgeFilterOperation.cc
index 4e956bdc50deaa45161301719184de7101aac8b3..cdfeb9b5ac6af802accc1f765ddd2a2a94ed6331 100644
--- a/source/blender/compositor/operations/COM_ConvolutionEdgeFilterOperation.cc
+++ b/source/blender/compositor/operations/COM_ConvolutionEdgeFilterOperation.cc
@@ -74,10 +74,10 @@ void ConvolutionEdgeFilterOperation::execute_pixel(float output[4], int x, int y
   output[3] = in2[3];
 
   /* Make sure we don't return negative color. */
-  output[0] = MAX2(output[0], 0.0f);
-  output[1] = MAX2(output[1], 0.0f);
-  output[2] = MAX2(output[2], 0.0f);
-  output[3] = MAX2(output[3], 0.0f);
+  output[0] = std::max(output[0], 0.0f);
+  output[1] = std::max(output[1], 0.0f);
+  output[2] = std::max(output[2], 0.0f);
+  output[3] = std::max(output[3], 0.0f);
 }
 
 void ConvolutionEdgeFilterOperation::update_memory_buffer_partial(MemoryBuffer *output,
diff --git a/source/blender/compositor/operations/COM_ConvolutionFilterOperation.cc b/source/blender/compositor/operations/COM_ConvolutionFilterOperation.cc
index 78040661cf11191cc6e7cada1ecb7b212e277341..42728282bef5c21b9581e15550609fa3910ae909 100644
--- a/source/blender/compositor/operations/COM_ConvolutionFilterOperation.cc
+++ b/source/blender/compositor/operations/COM_ConvolutionFilterOperation.cc
@@ -90,10 +90,10 @@ void ConvolutionFilterOperation::execute_pixel(float output[4], int x, int y, vo
   output[3] = output[3] * value[0] + in2[3] * mval;
 
   /* Make sure we don't return negative color. */
-  output[0] = MAX2(output[0], 0.0f);
-  output[1] = MAX2(output[1], 0.0f);
-  output[2] = MAX2(output[2], 0.0f);
-  output[3] = MAX2(output[3], 0.0f);
+  output[0] = std::max(output[0], 0.0f);
+  output[1] = std::max(output[1], 0.0f);
+  output[2] = std::max(output[2], 0.0f);
+  output[3] = std::max(output[3], 0.0f);
 }
 
 bool ConvolutionFilterOperation::determine_depending_area_of_interest(
diff --git a/source/blender/compositor/operations/COM_EllipseMaskOperation.cc b/source/blender/compositor/operations/COM_EllipseMaskOperation.cc
index f11c9a69386ff0b12ce69f124235cf4d6bf2790e..3379b6a7cf3439c47c9dd0f834a06951741bced5 100644
--- a/source/blender/compositor/operations/COM_EllipseMaskOperation.cc
+++ b/source/blender/compositor/operations/COM_EllipseMaskOperation.cc
@@ -34,8 +34,8 @@ void EllipseMaskOperation::execute_pixel_sampled(float output[4],
   float input_mask[4];
   float input_value[4];
 
-  float rx = x / MAX2(this->get_width() - 1.0f, FLT_EPSILON);
-  float ry = y / MAX2(this->get_height() - 1.0f, FLT_EPSILON);
+  float rx = x / std::max(this->get_width() - 1.0f, FLT_EPSILON);
+  float ry = y / std::max(this->get_height() - 1.0f, FLT_EPSILON);
 
   const float dy = (ry - data_->y) / aspect_ratio_;
   const float dx = rx - data_->x;
@@ -138,8 +138,8 @@ void EllipseMaskOperation::apply_mask(MemoryBuffer *output,
 {
   const MemoryBuffer *input_mask = inputs[0];
   const MemoryBuffer *input_value = inputs[1];
-  const float op_last_x = MAX2(this->get_width() - 1.0f, FLT_EPSILON);
-  const float op_last_y = MAX2(this->get_height() - 1.0f, FLT_EPSILON);
+  const float op_last_x = std::max(this->get_width() - 1.0f, FLT_EPSILON);
+  const float op_last_y = std::max(this->get_height() - 1.0f, FLT_EPSILON);
   const float half_w = data_->width / 2.0f;
   const float half_h = data_->height / 2.0f;
   const float tx = half_w * half_w;
diff --git a/source/blender/compositor/operations/COM_GlareThresholdOperation.cc b/source/blender/compositor/operations/COM_GlareThresholdOperation.cc
index 1e8c2689a765620498fe03d29a20926361859180..94f257f4834348196b4e0c380de01e4142df7c23 100644
--- a/source/blender/compositor/operations/COM_GlareThresholdOperation.cc
+++ b/source/blender/compositor/operations/COM_GlareThresholdOperation.cc
@@ -44,9 +44,9 @@ void GlareThresholdOperation::execute_pixel_sampled(float output[4],
     output[1] -= threshold;
     output[2] -= threshold;
 
-    output[0] = MAX2(output[0], 0.0f);
-    output[1] = MAX2(output[1], 0.0f);
-    output[2] = MAX2(output[2], 0.0f);
+    output[0] = std::max(output[0], 0.0f);
+    output[1] = std::max(output[1], 0.0f);
+    output[2] = std::max(output[2], 0.0f);
   }
   else {
     zero_v3(output);
diff --git a/source/blender/compositor/operations/COM_LuminanceMatteOperation.cc b/source/blender/compositor/operations/COM_LuminanceMatteOperation.cc
index 5469501dccdec81e77d36f4243fab64320d18508..99f90946ae0d23a4dec245a5e99d0dee7b696efc 100644
--- a/source/blender/compositor/operations/COM_LuminanceMatteOperation.cc
+++ b/source/blender/compositor/operations/COM_LuminanceMatteOperation.cc
@@ -42,7 +42,8 @@ void LuminanceMatteOperation::execute_pixel_sampled(float output[4],
   float alpha;
 
   /* one line thread-friend algorithm:
-   * output[0] = MIN2(input_value[3], MIN2(1.0f, MAX2(0.0f, ((luminance - low) / (high - low))));
+   * output[0] = std::min(input_value[3], std::min(1.0f, std::max(0.0f, ((luminance - low) / (high
+   * - low))));
    */
 
   /* test range */
@@ -73,7 +74,8 @@ void LuminanceMatteOperation::update_memory_buffer_partial(MemoryBuffer *output,
     const float luminance = IMB_colormanagement_get_luminance(color);
 
     /* One line thread-friend algorithm:
-     * `it.out[0] = MIN2(color[3], MIN2(1.0f, MAX2(0.0f, ((luminance - low) / (high - low))));`
+     * `it.out[0] = std::min(color[3], std::min(1.0f, std::max(0.0f, ((luminance - low) / (high -
+     * low))));`
      */
 
     /* Test range. */
@@ -95,7 +97,7 @@ void LuminanceMatteOperation::update_memory_buffer_partial(MemoryBuffer *output,
      */
 
     /* Don't make something that was more transparent less transparent. */
-    it.out[0] = MIN2(alpha, color[3]);
+    it.out[0] = std::min(alpha, color[3]);
   }
 }
 
diff --git a/source/blender/compositor/operations/COM_MaskOperation.h b/source/blender/compositor/operations/COM_MaskOperation.h
index 22009fac60e7b9a9ea618a4f5c75264c2dab3f01..498231771be84b72284a0841d2404899ee168e11 100644
--- a/source/blender/compositor/operations/COM_MaskOperation.h
+++ b/source/blender/compositor/operations/COM_MaskOperation.h
@@ -83,7 +83,7 @@ class MaskOperation : public MultiThreadedOperation {
 
   void set_motion_blur_samples(int samples)
   {
-    raster_mask_handle_tot_ = MIN2(MAX2(1, samples), CMP_NODE_MASK_MBLUR_SAMPLES_MAX);
+    raster_mask_handle_tot_ = std::min(std::max(1, samples), CMP_NODE_MASK_MBLUR_SAMPLES_MAX);
   }
   void set_motion_blur_shutter(float shutter)
   {
diff --git a/source/blender/compositor/operations/COM_MathBaseOperation.cc b/source/blender/compositor/operations/COM_MathBaseOperation.cc
index 5d65014f88809dfb110239bdec305ff8693a10c1..35cd7caf60587c7646580204c220b4ef8f7b4f61 100644
--- a/source/blender/compositor/operations/COM_MathBaseOperation.cc
+++ b/source/blender/compositor/operations/COM_MathBaseOperation.cc
@@ -468,7 +468,7 @@ void MathMinimumOperation::execute_pixel_sampled(float output[4],
   input_value1_operation_->read_sampled(input_value1, x, y, sampler);
   input_value2_operation_->read_sampled(input_value2, x, y, sampler);
 
-  output[0] = MIN2(input_value1[0], input_value2[0]);
+  output[0] = std::min(input_value1[0], input_value2[0]);
 
   clamp_if_needed(output);
 }
@@ -476,7 +476,7 @@ void MathMinimumOperation::execute_pixel_sampled(float output[4],
 void MathMinimumOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
 {
   for (; !it.is_end(); ++it) {
-    *it.out = MIN2(*it.in(0), *it.in(1));
+    *it.out = std::min(*it.in(0), *it.in(1));
     clamp_when_enabled(it.out);
   }
 }
@@ -492,7 +492,7 @@ void MathMaximumOperation::execute_pixel_sampled(float output[4],
   input_value1_operation_->read_sampled(input_value1, x, y, sampler);
   input_value2_operation_->read_sampled(input_value2, x, y, sampler);
 
-  output[0] = MAX2(input_value1[0], input_value2[0]);
+  output[0] = std::max(input_value1[0], input_value2[0]);
 
   clamp_if_needed(output);
 }
@@ -500,7 +500,7 @@ void MathMaximumOperation::execute_pixel_sampled(float output[4],
 void MathMaximumOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
 {
   for (; !it.is_end(); ++it) {
-    *it.out = MAX2(*it.in(0), *it.in(1));
+    *it.out = std::max(*it.in(0), *it.in(1));
     clamp_when_enabled(it.out);
   }
 }
@@ -1007,7 +1007,7 @@ void MathCompareOperation::execute_pixel_sampled(float output[4],
 void MathCompareOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
 {
   for (; !it.is_end(); ++it) {
-    *it.out = (fabsf(*it.in(0) - *it.in(1)) <= MAX2(*it.in(2), 1e-5f)) ? 1.0f : 0.0f;
+    *it.out = (fabsf(*it.in(0) - *it.in(1)) <= std::max(*it.in(2), 1e-5f)) ? 1.0f : 0.0f;
     clamp_when_enabled(it.out);
   }
 }
diff --git a/source/blender/compositor/operations/COM_MixOperation.cc b/source/blender/compositor/operations/COM_MixOperation.cc
index 25c3870207a4cf1e5f81774c862cadd09e621062..707067caf7c605e27e4b8c9f79d6065b65977543 100644
--- a/source/blender/compositor/operations/COM_MixOperation.cc
+++ b/source/blender/compositor/operations/COM_MixOperation.cc
@@ -803,9 +803,9 @@ void MixGlareOperation::execute_pixel_sampled(float output[4],
     input_weight = 1.0f - value;
     glare_weight = 1.0f;
   }
-  output[0] = input_weight * MAX2(input_color1[0], 0.0f) + glare_weight * input_color2[0];
-  output[1] = input_weight * MAX2(input_color1[1], 0.0f) + glare_weight * input_color2[1];
-  output[2] = input_weight * MAX2(input_color1[2], 0.0f) + glare_weight * input_color2[2];
+  output[0] = input_weight * std::max(input_color1[0], 0.0f) + glare_weight * input_color2[0];
+  output[1] = input_weight * std::max(input_color1[1], 0.0f) + glare_weight * input_color2[1];
+  output[2] = input_weight * std::max(input_color1[2], 0.0f) + glare_weight * input_color2[2];
   output[3] = input_color1[3];
 
   clamp_if_needed(output);
@@ -828,9 +828,9 @@ void MixGlareOperation::update_memory_buffer_row(PixelCursor &p)
       input_weight = 1.0f - value;
       glare_weight = 1.0f;
     }
-    p.out[0] = input_weight * MAX2(p.color1[0], 0.0f) + glare_weight * p.color2[0];
-    p.out[1] = input_weight * MAX2(p.color1[1], 0.0f) + glare_weight * p.color2[1];
-    p.out[2] = input_weight * MAX2(p.color1[2], 0.0f) + glare_weight * p.color2[2];
+    p.out[0] = input_weight * std::max(p.color1[0], 0.0f) + glare_weight * p.color2[0];
+    p.out[1] = input_weight * std::max(p.color1[1], 0.0f) + glare_weight * p.color2[1];
+    p.out[2] = input_weight * std::max(p.color1[2], 0.0f) + glare_weight * p.color2[2];
     p.out[3] = p.color1[3];
 
     clamp_if_needed(p.out);
@@ -963,13 +963,13 @@ void MixLightenOperation::update_memory_buffer_row(PixelCursor &p)
     }
 
     float tmp = value * p.color2[0];
-    p.out[0] = MAX2(tmp, p.color1[0]);
+    p.out[0] = std::max(tmp, p.color1[0]);
 
     tmp = value * p.color2[1];
-    p.out[1] = MAX2(tmp, p.color1[1]);
+    p.out[1] = std::max(tmp, p.color1[1]);
 
     tmp = value * p.color2[2];
-    p.out[2] = MAX2(tmp, p.color1[2]);
+    p.out[2] = std::max(tmp, p.color1[2]);
 
     p.out[3] = p.color1[3];
 
diff --git a/source/blender/compositor/operations/COM_RotateOperation.cc b/source/blender/compositor/operations/COM_RotateOperation.cc
index 9b5104885ecf91a34e33a7e1ae6c15d5e14d1791..d4d693642040da3ff29eb98388c1e5386a8151eb 100644
--- a/source/blender/compositor/operations/COM_RotateOperation.cc
+++ b/source/blender/compositor/operations/COM_RotateOperation.cc
@@ -57,10 +57,10 @@ void RotateOperation::get_area_rotation_bounds(const rcti &area,
   const float y2 = center_y + (sine * dxmax + cosine * dymin);
   const float y3 = center_y + (sine * dxmin + cosine * dymax);
   const float y4 = center_y + (sine * dxmax + cosine * dymax);
-  const float minx = MIN2(x1, MIN2(x2, MIN2(x3, x4)));
-  const float maxx = std::max(x1, MAX2(x2, std::max(x3, x4)));
-  const float miny = MIN2(y1, std::min(y2, MIN2(y3, y4)));
-  const float maxy = std::max(y1, MAX2(y2, std::max(y3, y4)));
+  const float minx = std::min(x1, std::min(x2, std::min(x3, x4)));
+  const float maxx = std::max(x1, std::max(x2, std::max(x3, x4)));
+  const float miny = std::min(y1, std::min(y2, std::min(y3, y4)));
+  const float maxy = std::max(y1, std::max(y2, std::max(y3, y4)));
 
   r_bounds.xmin = floor(minx);
   r_bounds.xmax = ceil(maxx);
diff --git a/source/blender/compositor/operations/COM_ScaleOperation.h b/source/blender/compositor/operations/COM_ScaleOperation.h
index dfcf08542afafd65059d559028fdaa753eaec0d2..25895ba7a266cd489c8905ebb0dcc4e8e60d2c3b 100644
--- a/source/blender/compositor/operations/COM_ScaleOperation.h
+++ b/source/blender/compositor/operations/COM_ScaleOperation.h
@@ -54,14 +54,14 @@ class ScaleOperation : public BaseScaleOperation {
 
   static float scale_coord(const float coord, const float center, const float relative_scale)
   {
-    return center + (coord - center) * MAX2(relative_scale, MIN_RELATIVE_SCALE);
+    return center + (coord - center) * std::max(relative_scale, MIN_RELATIVE_SCALE);
   }
 
   static float scale_coord_inverted(const float coord,
                                     const float center,
                                     const float relative_scale)
   {
-    return center + (coord - center) / MAX2(relative_scale, MIN_RELATIVE_SCALE);
+    return center + (coord - center) / std::max(relative_scale, MIN_RELATIVE_SCALE);
   }
 
   static void get_scale_offset(const rcti &input_canvas,
diff --git a/source/blender/compositor/operations/COM_TonemapOperation.cc b/source/blender/compositor/operations/COM_TonemapOperation.cc
index baba168e9d450b300f90bae23d43c8ccfa8e323c..949f5ff4229c686bb91bd0eb89b273c09c6c625d 100644
--- a/source/blender/compositor/operations/COM_TonemapOperation.cc
+++ b/source/blender/compositor/operations/COM_TonemapOperation.cc
@@ -41,7 +41,7 @@ void TonemapOperation::execute_pixel(float output[4], int x, int y, void *data)
   const float igm = avg->igm;
   if (igm != 0.0f) {
     output[0] = powf(std::max(output[0], 0.0f), igm);
-    output[1] = powf(MAX2(output[1], 0.0f), igm);
+    output[1] = powf(std::max(output[1], 0.0f), igm);
     output[2] = powf(std::max(output[2], 0.0f), igm);
   }
 }
@@ -115,7 +115,7 @@ void *TonemapOperation::initialize_tile_data(rcti *rect)
       float L = IMB_colormanagement_get_luminance(bc);
       Lav += L;
       add_v3_v3(cav, bc);
-      lsum += logf(MAX2(L, 0.0f) + 1e-5f);
+      lsum += logf(std::max(L, 0.0f) + 1e-5f);
       maxl = (L > maxl) ? L : maxl;
       minl = (L < minl) ? L : minl;
       bc += 4;
@@ -164,9 +164,9 @@ static Luminance calc_area_luminance(const MemoryBuffer *input, const rcti &area
     const float lu = IMB_colormanagement_get_luminance(elem);
     lum.sum += lu;
     add_v3_v3(lum.color_sum, elem);
-    lum.log_sum += logf(MAX2(lu, 0.0f) + 1e-5f);
-    lum.max = MAX2(lu, lum.max);
-    lum.min = MIN2(lu, lum.min);
+    lum.log_sum += logf(std::max(lu, 0.0f) + 1e-5f);
+    lum.max = std::max(lu, lum.max);
+    lum.min = std::min(lu, lum.min);
     lum.num_pixels++;
   }
   return lum;
@@ -235,8 +235,8 @@ void TonemapOperation::update_memory_buffer_partial(MemoryBuffer *output,
     it.out[1] /= ((dg == 0.0f) ? 1.0f : dg);
     it.out[2] /= ((db == 0.0f) ? 1.0f : db);
     if (igm != 0.0f) {
-      it.out[0] = powf(MAX2(it.out[0], 0.0f), igm);
-      it.out[1] = powf(MAX2(it.out[1], 0.0f), igm);
+      it.out[0] = powf(std::max(it.out[0], 0.0f), igm);
+      it.out[1] = powf(std::max(it.out[1], 0.0f), igm);
       it.out[2] = powf(std::max(it.out[2], 0.0f), igm);
     }
   }
diff --git a/source/blender/compositor/operations/COM_VectorBlurOperation.cc b/source/blender/compositor/operations/COM_VectorBlurOperation.cc
index e155629bc19607c1e63bd82da8d8a30074131c44..c3311bea5c9bb8c9e0e87390d52cf7292c8174c3 100644
--- a/source/blender/compositor/operations/COM_VectorBlurOperation.cc
+++ b/source/blender/compositor/operations/COM_VectorBlurOperation.cc
@@ -906,7 +906,7 @@ void zbuf_accumulate_vecblur(NodeBlurData *nbd,
           dz2[3] += bfac * dr->colpoin[3];
 
           *rw += bfac;
-          *rm = MAX2(*rm, bfac);
+          *rm = std::max(*rm, bfac);
         }
       }
     }
diff --git a/source/blender/datatoc/datatoc.cc b/source/blender/datatoc/datatoc.cc
index 4147b1a0af373795f44da6cc4084eb411aed3d8e..bb1d7c2f2fdd4154ba2e76c93ea746785065dd20 100644
--- a/source/blender/datatoc/datatoc.cc
+++ b/source/blender/datatoc/datatoc.cc
@@ -6,15 +6,13 @@
  * \ingroup datatoc
  */
 
+#include <algorithm>
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
 
 /* #define VERBOSE */
 
-#define MAX2(x, y) ((x) > (y) ? (x) : (y))
-#define MAX3(x, y, z) MAX2(MAX2((x), (y)), (z))
-
 #define STRPREFIX(a, b) (strncmp((a), (b), strlen(b)) == 0)
 
 static char *arg_basename(char *string)
@@ -30,7 +28,7 @@ static char *arg_basename(char *string)
     lfslash++;
   }
 
-  return MAX3(string, lfslash, lbslash);
+  return std::max({string, lfslash, lbslash});
 }
 
 /**
diff --git a/source/blender/draw/engines/eevee/eevee_lightcache.cc b/source/blender/draw/engines/eevee/eevee_lightcache.cc
index ad1d9474d2fa5ecce44e0cbd3f09d4a134df7354..f43b920340df4e71dfa56b67def8a195cf00e949 100644
--- a/source/blender/draw/engines/eevee/eevee_lightcache.cc
+++ b/source/blender/draw/engines/eevee/eevee_lightcache.cc
@@ -1098,8 +1098,8 @@ static void compute_cell_id(EEVEE_LightGrid *egrid,
                          probe->grid_resolution_z;
 
   /* Add one for level 0 */
-  int max_lvl = int(floorf(log2f(
-      float(MAX3(probe->grid_resolution_x, probe->grid_resolution_y, probe->grid_resolution_z)))));
+  int max_lvl = int(floorf(log2f(float(
+      std::max({probe->grid_resolution_x, probe->grid_resolution_y, probe->grid_resolution_z})))));
 
   int visited_cells = 0;
   *r_stride = 0;
diff --git a/source/blender/draw/intern/draw_manager_profiling.cc b/source/blender/draw/intern/draw_manager_profiling.cc
index 94ce41a9bec82e0ee8f92e0edd97be11504c81b2..db6849321300fd692b869f46500c60523e911f9f 100644
--- a/source/blender/draw/intern/draw_manager_profiling.cc
+++ b/source/blender/draw/intern/draw_manager_profiling.cc
@@ -6,6 +6,8 @@
  * \ingroup draw
  */
 
+#include <algorithm>
+
 #include "BLI_listbase.h"
 #include "BLI_rect.h"
 #include "BLI_string.h"
@@ -178,7 +180,7 @@ void DRW_stats_reset()
 
         timer->time_average = timer->time_average * (1.0 - GPU_TIMER_FALLOFF) +
                               time * GPU_TIMER_FALLOFF;
-        timer->time_average = MIN2(timer->time_average, 1000000000);
+        timer->time_average = std::min(timer->time_average, uint64_t(1000000000));
       }
       else {
         timer->time_average = lvl_time[timer->lvl + 1];
diff --git a/source/blender/editors/animation/keyframes_keylist.cc b/source/blender/editors/animation/keyframes_keylist.cc
index 3104a0bd43cd524bae41fd22d9e3a52b9c1c43a2..089ed42b5675da1f0fa21cc82a919f2a1a61029f 100644
--- a/source/blender/editors/animation/keyframes_keylist.cc
+++ b/source/blender/editors/animation/keyframes_keylist.cc
@@ -885,7 +885,7 @@ static void update_keyblocks(AnimKeylist *keylist, BezTriple *bezt, const int be
   int max_curve = 0;
 
   LISTBASE_FOREACH (ActKeyColumn *, col, &keylist->key_columns) {
-    max_curve = MAX2(max_curve, col->totcurve);
+    max_curve = std::max(max_curve, int(col->totcurve));
   }
 
   /* Propagate blocks to inserted keys. */
diff --git a/source/blender/editors/gpencil_legacy/gpencil_data.cc b/source/blender/editors/gpencil_legacy/gpencil_data.cc
index 22cf6fe63782b612626137da33310c649093a624..af80482fc31efedeba7ab9367708fcb2a2318ca4 100644
--- a/source/blender/editors/gpencil_legacy/gpencil_data.cc
+++ b/source/blender/editors/gpencil_legacy/gpencil_data.cc
@@ -8,6 +8,7 @@
  * Operators for dealing with GP data-blocks and layers.
  */
 
+#include <algorithm>
 #include <cmath>
 #include <cstddef>
 #include <cstdio>
@@ -2729,7 +2730,7 @@ static int gpencil_vertex_group_normalize_all_exec(bContext *C, wmOperator *op)
       }
 
       /* Normalize weights. */
-      float fac = MAX2(0, (1.0f - sum_lock) / sum_unlock);
+      float fac = std::max(0.0f, (1.0f - sum_lock) / sum_unlock);
 
       for (v = 0; v < defbase_tot; v++) {
         /* Get vertex group. */
diff --git a/source/blender/editors/gpencil_legacy/gpencil_utils.cc b/source/blender/editors/gpencil_legacy/gpencil_utils.cc
index a3b65d5bb6a1d4c11d5d45d87f569a1a7d3d4089..b4d4396c7109e2eb7cd1fe2624ba6f0b4978512b 100644
--- a/source/blender/editors/gpencil_legacy/gpencil_utils.cc
+++ b/source/blender/editors/gpencil_legacy/gpencil_utils.cc
@@ -6,6 +6,7 @@
  * \ingroup edgpencil
  */
 
+#include <algorithm>
 #include <cmath>
 #include <cstddef>
 #include <cstdio>
@@ -1770,7 +1771,7 @@ float ED_gpencil_cursor_radius(bContext *C, int x, int y)
     point2D.m_xy[0] = float(x + 64);
     gpencil_stroke_convertcoords_tpoint(scene, region, ob, &point2D, nullptr, p2);
     /* Clip extreme zoom level (and avoid division by zero). */
-    distance = MAX2(len_v3v3(p1, p2), 0.001f);
+    distance = std::max(len_v3v3(p1, p2), 0.001f);
 
     /* Handle layer thickness change. */
     float brush_size = float(brush->size);
diff --git a/source/blender/editors/interface/interface_icons.cc b/source/blender/editors/interface/interface_icons.cc
index a9046f859545debd289dd99e4599d784cf09b800..dc8c0115adc591d6d9ed81079460ca02847b6789 100644
--- a/source/blender/editors/interface/interface_icons.cc
+++ b/source/blender/editors/interface/interface_icons.cc
@@ -6,6 +6,7 @@
  * \ingroup edinterface
  */
 
+#include <algorithm>
 #include <cmath>
 #include <cstdlib>
 #include <cstring>
@@ -798,10 +799,10 @@ static ImBuf *create_mono_icon_with_border(ImBuf *buf,
       const int blur_size = 2 / resolution_divider;
       for (int bx = 0; bx < icon_width; bx++) {
         const int asx = std::max(bx - blur_size, 0);
-        const int aex = MIN2(bx + blur_size + 1, icon_width);
+        const int aex = std::min(bx + blur_size + 1, icon_width);
         for (int by = 0; by < icon_height; by++) {
           const int asy = std::max(by - blur_size, 0);
-          const int aey = MIN2(by + blur_size + 1, icon_height);
+          const int aey = std::min(by + blur_size + 1, icon_height);
 
           /* blur alpha channel */
           const int write_offset = by * (ICON_GRID_W + 2 * ICON_MONO_BORDER_OUTSET) + bx;
@@ -2584,7 +2585,7 @@ ImBuf *UI_icon_alert_imbuf_get(eAlertIcon icon)
   return nullptr;
 #else
   const int ALERT_IMG_SIZE = 256;
-  icon = eAlertIcon(MIN2(icon, ALERT_ICON_MAX - 1));
+  icon = eAlertIcon(std::min<int>(icon, ALERT_ICON_MAX - 1));
   const int left = icon * ALERT_IMG_SIZE;
   const rcti crop = {left, left + ALERT_IMG_SIZE - 1, 0, ALERT_IMG_SIZE - 1};
   ImBuf *ibuf = IMB_ibImageFromMemory((const uchar *)datatoc_alert_icons_png,
diff --git a/source/blender/editors/interface/interface_layout.cc b/source/blender/editors/interface/interface_layout.cc
index 3919328fdb27fb615dc47bd68f30bb4a26bff846..4c1e03063b87ec513c1a15e58a25eccf7842504f 100644
--- a/source/blender/editors/interface/interface_layout.cc
+++ b/source/blender/editors/interface/interface_layout.cc
@@ -6,6 +6,7 @@
  * \ingroup edinterface
  */
 
+#include <algorithm>
 #include <climits>
 #include <cmath>
 #include <cstdlib>
@@ -4302,7 +4303,7 @@ static void ui_litem_estimate_column_flow(uiLayout *litem)
   int totitem = 0;
   LISTBASE_FOREACH (uiItem *, item, &litem->items) {
     ui_item_size(item, &itemw, &itemh);
-    maxw = MAX2(maxw, itemw);
+    maxw = std::max(maxw, itemw);
     toth += itemh;
     totitem++;
   }
@@ -6382,7 +6383,7 @@ uiLayout *uiItemsAlertBox(uiBlock *block, const int size, const eAlertIcon icon)
 {
   const uiStyle *style = UI_style_get_dpi();
   const short icon_size = 64 * UI_SCALE_FAC;
-  const int text_points_max = MAX2(style->widget.points, style->widgetlabel.points);
+  const int text_points_max = std::max(style->widget.points, style->widgetlabel.points);
   const int dialog_width = icon_size + (text_points_max * size * UI_SCALE_FAC);
   /* By default, the space between icon and text/buttons will be equal to the 'columnspace',
    * this extra padding will add some space by increasing the left column width,
diff --git a/source/blender/editors/interface/interface_region_menu_popup.cc b/source/blender/editors/interface/interface_region_menu_popup.cc
index 8e1473fb373e36c65f425189c174e826e12a5c83..7e9b80e9ec3eabdfd40781ce9293e793ee6f68dd 100644
--- a/source/blender/editors/interface/interface_region_menu_popup.cc
+++ b/source/blender/editors/interface/interface_region_menu_popup.cc
@@ -8,6 +8,7 @@
  * PopUp Menu Region
  */
 
+#include <algorithm>
 #include <cstdarg>
 #include <cstdlib>
 #include <cstring>
@@ -592,7 +593,7 @@ void UI_popup_menu_reports(bContext *C, ReportList *reports)
       msg_next = strchr(msg, '\n');
       if (msg_next) {
         msg_next++;
-        BLI_strncpy(buf, msg, MIN2(sizeof(buf), msg_next - msg));
+        BLI_strncpy(buf, msg, std::min(sizeof(buf), size_t(msg_next - msg)));
         msg = buf;
       }
       uiItemL(layout, msg, icon);
diff --git a/source/blender/editors/interface/interface_region_tooltip.cc b/source/blender/editors/interface/interface_region_tooltip.cc
index 888f7dcd215791db164d59e0aef9a0a8768fbd5d..454b869d66d4719b090595a1ccf4889e41092e80 100644
--- a/source/blender/editors/interface/interface_region_tooltip.cc
+++ b/source/blender/editors/interface/interface_region_tooltip.cc
@@ -17,6 +17,7 @@
  * For now it's not a priority, so leave as-is.
  */
 
+#include <algorithm>
 #include <cstdarg>
 #include <cstdlib>
 #include <cstring>
diff --git a/source/blender/editors/interface/interface_template_list.cc b/source/blender/editors/interface/interface_template_list.cc
index f168a415190f9718f7ed59c952e04618f410b2b8..99702c803299a192ad2e20818bbfe21e18b2b31d 100644
--- a/source/blender/editors/interface/interface_template_list.cc
+++ b/source/blender/editors/interface/interface_template_list.cc
@@ -6,6 +6,7 @@
  * \ingroup edinterface
  */
 
+#include <algorithm>
 #include <cstdlib>
 #include <cstring>
 
@@ -1006,7 +1007,8 @@ static void ui_template_list_layout_draw(const bContext *C,
       const int size_x = UI_preview_tile_size_x();
       const int size_y = show_names ? UI_preview_tile_size_y() : UI_preview_tile_size_y_no_label();
 
-      const int cols_per_row = MAX2((uiLayoutGetWidth(box) - V2D_SCROLL_WIDTH) / size_x, 1);
+      const int cols_per_row = std::max(int((uiLayoutGetWidth(box) - V2D_SCROLL_WIDTH) / size_x),
+                                        1);
       uiLayout *grid = uiLayoutGridFlow(row, true, cols_per_row, true, true, true);
 
       TemplateListLayoutDrawData adjusted_layout_data = *layout_data;
diff --git a/source/blender/editors/interface/interface_templates.cc b/source/blender/editors/interface/interface_templates.cc
index 9a4504736ba3f426c4ed3572da922873b3933287..863b2a157349c25821d7856022b1da230899c5b6 100644
--- a/source/blender/editors/interface/interface_templates.cc
+++ b/source/blender/editors/interface/interface_templates.cc
@@ -6,6 +6,7 @@
  * \ingroup edinterface
  */
 
+#include <algorithm>
 #include <cctype>
 #include <cstddef>
 #include <cstdlib>
@@ -7272,7 +7273,7 @@ static void uiTemplateRecentFiles_tooltip_func(bContext * /*C*/, uiTooltipData *
   }
 
   if (thumb) {
-    float scale = (72.0f * UI_SCALE_FAC) / float(MAX2(thumb->x, thumb->y));
+    float scale = (72.0f * UI_SCALE_FAC) / float(std::max(thumb->x, thumb->y));
     short size[2] = {short(float(thumb->x) * scale), short(float(thumb->y) * scale)};
     UI_tooltip_text_field_add(tip, {}, {}, UI_TIP_STYLE_SPACER, UI_TIP_LC_NORMAL);
     UI_tooltip_text_field_add(tip, {}, {}, UI_TIP_STYLE_SPACER, UI_TIP_LC_NORMAL);
diff --git a/source/blender/editors/interface/interface_widgets.cc b/source/blender/editors/interface/interface_widgets.cc
index 4b0d22e5c051cf9be7ee6bc3747e6d2867ea2920..373d466fb573cefe6639359750c14b14cc4b1e9e 100644
--- a/source/blender/editors/interface/interface_widgets.cc
+++ b/source/blender/editors/interface/interface_widgets.cc
@@ -6,6 +6,7 @@
  * \ingroup edinterface
  */
 
+#include <algorithm>
 #include <climits>
 #include <cstdlib>
 #include <cstring>
@@ -2846,7 +2847,7 @@ static void ui_hsv_cursor(const float x,
   immUniform1f("outlineWidth", U.pixelsize);
 
   /* Alpha of outline colors just strong enough to give good contrast. */
-  const float fg = MIN2(1.0f - hsv[2] + 0.2, 0.8f);
+  const float fg = std::min(1.0f - hsv[2] + 0.2f, 0.8f);
   const float bg = hsv[2] / 2.0f;
 
   immUniform4f("outlineColor", 0.0f, 0.0f, 0.0f, bg);
diff --git a/source/blender/editors/interface/view2d_draw.cc b/source/blender/editors/interface/view2d_draw.cc
index 6c5f42a45bd020d8afa8b63c868a48f4dd3e5cf9..d9fec3d8a027ca34f4abb817a2cfb5f37865fa93 100644
--- a/source/blender/editors/interface/view2d_draw.cc
+++ b/source/blender/editors/interface/view2d_draw.cc
@@ -6,6 +6,7 @@
  * \ingroup edinterface
  */
 
+#include <algorithm>
 #include <cfloat>
 #include <climits>
 #include <cmath>
@@ -148,7 +149,7 @@ static void get_parallel_lines_draw_steps(const ParallelLinesSet *lines,
              lines->offset;
 
   if (region_start <= *r_first && region_end >= *r_first) {
-    *r_steps = MAX2(0, floorf((region_end - *r_first) / lines->distance)) + 1;
+    *r_steps = std::max(0.0f, floorf((region_end - *r_first) / lines->distance)) + 1;
   }
   else {
     *r_steps = 0;
diff --git a/source/blender/editors/mask/mask_add.cc b/source/blender/editors/mask/mask_add.cc
index a62e46c486cc108a2fb9be4c284a5e882f7e921c..e731303aa0dd92a8ddea5f28669df2535d8a4a6a 100644
--- a/source/blender/editors/mask/mask_add.cc
+++ b/source/blender/editors/mask/mask_add.cc
@@ -6,6 +6,8 @@
  * \ingroup edmask
  */
 
+#include <algorithm>
+
 #include "MEM_guardedalloc.h"
 
 #include "BKE_context.hh"
@@ -85,13 +87,13 @@ static void setup_vertex_point(Mask *mask,
 
         current_point = &spline->points[point_index];
         if (current_point->bezt.h1 != HD_VECT || current_point->bezt.h2 != HD_VECT) {
-          bezt->h1 = bezt->h2 = MAX2(current_point->bezt.h2, current_point->bezt.h1);
+          bezt->h1 = bezt->h2 = std::max(current_point->bezt.h2, current_point->bezt.h1);
           break;
         }
       }
     }
     else {
-      bezt->h1 = bezt->h2 = MAX2(reference_point->bezt.h2, reference_point->bezt.h1);
+      bezt->h1 = bezt->h2 = std::max(reference_point->bezt.h2, reference_point->bezt.h1);
     }
 
     reference_parent_point = reference_point;
@@ -121,12 +123,12 @@ static void setup_vertex_point(Mask *mask,
       }
 
       /* handle type */
-      char handle_type = 0;
+      uint8_t handle_type = 0;
       if (prev_point) {
         handle_type = prev_point->bezt.h2;
       }
       if (next_point) {
-        handle_type = MAX2(next_point->bezt.h2, handle_type);
+        handle_type = std::max(next_point->bezt.h2, handle_type);
       }
       bezt->h1 = bezt->h2 = handle_type;
 
diff --git a/source/blender/editors/mesh/meshtools.cc b/source/blender/editors/mesh/meshtools.cc
index ae2da39834ec28b54c8c41350ff5e69641fded19..70b44aa5aaf28e5a0b9bd025da42b8ba1f5a6ec6 100644
--- a/source/blender/editors/mesh/meshtools.cc
+++ b/source/blender/editors/mesh/meshtools.cc
@@ -9,6 +9,8 @@
  * tools operating on meshes
  */
 
+#include <algorithm>
+
 #include "MEM_guardedalloc.h"
 
 #include "BLI_math_matrix.h"
@@ -1049,12 +1051,12 @@ static uint mirror_facehash(const void *ptr)
   uint v0, v1;
 
   if (mf->v4) {
-    v0 = MIN4(mf->v1, mf->v2, mf->v3, mf->v4);
-    v1 = MAX4(mf->v1, mf->v2, mf->v3, mf->v4);
+    v0 = std::min({mf->v1, mf->v2, mf->v3, mf->v4});
+    v1 = std::max({mf->v1, mf->v2, mf->v3, mf->v4});
   }
   else {
-    v0 = MIN3(mf->v1, mf->v2, mf->v3);
-    v1 = MAX3(mf->v1, mf->v2, mf->v3);
+    v0 = std::min({mf->v1, mf->v2, mf->v3});
+    v1 = std::min({mf->v1, mf->v2, mf->v3});
   }
 
   return ((v0 * 39) ^ (v1 * 31));
diff --git a/source/blender/editors/physics/particle_edit.cc b/source/blender/editors/physics/particle_edit.cc
index c3b06b3c762ac6e34a4d09bbc8ac96a2c32bd099..3ce666f2fc243512a349201d81170a1501923f40 100644
--- a/source/blender/editors/physics/particle_edit.cc
+++ b/source/blender/editors/physics/particle_edit.cc
@@ -6,6 +6,7 @@
  * \ingroup edphys
  */
 
+#include <algorithm>
 #include <cmath>
 #include <cstdlib>
 #include <cstring>
@@ -4637,7 +4638,7 @@ static int brush_add(const bContext *C, PEData *data, short number)
           mul_v3_fl(key3[0].co, weight[0]);
 
           /* TODO: interpolating the weight would be nicer */
-          thkey->weight = (ppa->hair + MIN2(k, ppa->totkey - 1))->weight;
+          thkey->weight = (ppa->hair + std::min(k, ppa->totkey - 1))->weight;
 
           if (maxw > 1) {
             key3[1].time = key3[0].time;
diff --git a/source/blender/editors/render/render_preview.cc b/source/blender/editors/render/render_preview.cc
index c6ace64a283db5f27d658a5e978907399ebef1d8..3c49a45e2f444071ab7410326c61f48372845bf1 100644
--- a/source/blender/editors/render/render_preview.cc
+++ b/source/blender/editors/render/render_preview.cc
@@ -8,6 +8,7 @@
 
 /* global includes */
 
+#include <algorithm>
 #include <cmath>
 #include <cstdlib>
 #include <cstring>
@@ -1383,8 +1384,8 @@ static void icon_copy_rect(ImBuf *ibuf, uint w, uint h, uint *rect)
   }
 
   /* Scaling down must never assign zero width/height, see: #89868. */
-  ex = MAX2(1, short(scaledx));
-  ey = MAX2(1, short(scaledy));
+  ex = std::max(short(1), short(scaledx));
+  ey = std::max(short(1), short(scaledy));
 
   dx = (w - ex) / 2;
   dy = (h - ey) / 2;
diff --git a/source/blender/editors/screen/screen_edit.cc b/source/blender/editors/screen/screen_edit.cc
index 0a068a24da604a33af38de202f5236e9afdafd7a..3bffdc3e62cebfbf7ec90dd8a4fff1af5190bfc5 100644
--- a/source/blender/editors/screen/screen_edit.cc
+++ b/source/blender/editors/screen/screen_edit.cc
@@ -286,8 +286,8 @@ eScreenDir area_getorientation(ScrArea *sa_a, ScrArea *sa_b)
   short overlapy = std::min(top_a, top_b) - std::max(bottom_a, bottom_b);
 
   /* Minimum overlap required. */
-  const short minx = MIN3(AREAJOINTOLERANCEX, right_a - left_a, right_b - left_b);
-  const short miny = MIN3(AREAJOINTOLERANCEY, top_a - bottom_a, top_b - bottom_b);
+  const short minx = std::min({int(AREAJOINTOLERANCEX), right_a - left_a, right_b - left_b});
+  const short miny = std::min({int(AREAJOINTOLERANCEY), top_a - bottom_a, top_b - bottom_b});
 
   if (top_a == bottom_b && overlapx >= minx) {
     return eScreenDir(1); /* sa_a to bottom of sa_b = N */
diff --git a/source/blender/editors/screen/screen_geometry.cc b/source/blender/editors/screen/screen_geometry.cc
index 712d9efa6718153a6cf570d897fc55d7645cd507..08dd4c9072b443c0a2c858287952f0588a0d5e2a 100644
--- a/source/blender/editors/screen/screen_geometry.cc
+++ b/source/blender/editors/screen/screen_geometry.cc
@@ -84,7 +84,7 @@ ScrEdge *screen_geom_area_map_find_active_scredge(const ScrAreaMap *area_map,
     if (screen_geom_edge_is_horizontal(se)) {
       if ((se->v1->vec.y > bounds_rect->ymin) && (se->v1->vec.y < (bounds_rect->ymax - 1))) {
         short min, max;
-        min = MIN2(se->v1->vec.x, se->v2->vec.x);
+        min = std::min(se->v1->vec.x, se->v2->vec.x);
         max = std::max(se->v1->vec.x, se->v2->vec.x);
 
         if (abs(my - se->v1->vec.y) <= safety && mx >= min && mx <= max) {
@@ -95,7 +95,7 @@ ScrEdge *screen_geom_area_map_find_active_scredge(const ScrAreaMap *area_map,
     else {
       if ((se->v1->vec.x > bounds_rect->xmin) && (se->v1->vec.x < (bounds_rect->xmax - 1))) {
         short min, max;
-        min = MIN2(se->v1->vec.y, se->v2->vec.y);
+        min = std::min(se->v1->vec.y, se->v2->vec.y);
         max = std::max(se->v1->vec.y, se->v2->vec.y);
 
         if (abs(mx - se->v1->vec.x) <= safety && my >= min && my <= max) {
diff --git a/source/blender/editors/sculpt_paint/paint_image_2d.cc b/source/blender/editors/sculpt_paint/paint_image_2d.cc
index ef192a7216d1ba909be8d1da1f5f08b601310a55..4ec5527136d157872e12025b831eeee8f4c97196 100644
--- a/source/blender/editors/sculpt_paint/paint_image_2d.cc
+++ b/source/blender/editors/sculpt_paint/paint_image_2d.cc
@@ -692,7 +692,7 @@ static void brush_painter_2d_refresh_cache(ImagePaintState *s,
   Brush *brush = painter->brush;
   BrushPainterCache *cache = &tile->cache;
   /* Adding 4 pixels of padding for brush anti-aliasing. */
-  const int diameter = MAX2(1, size * 2) + 4;
+  const int diameter = std::max(1, int(size * 2)) + 4;
 
   bool do_random = false;
   bool do_partial_update = false;
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.cc b/source/blender/editors/sculpt_paint/paint_image_proj.cc
index d54964050dae6599ba5c61df5baa130fca17abcb..92493a2e737c3b2bf751b38428561c8fed289409 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.cc
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.cc
@@ -7,6 +7,7 @@
  * \brief Functions to paint images in 2D and 3D.
  */
 
+#include <algorithm>
 #include <cfloat>
 #include <climits>
 #include <cmath>
@@ -1375,7 +1376,7 @@ static void uv_image_outset(const ProjPaintState *ps,
       len_fact = UNLIKELY(len_fact < FLT_EPSILON) ? FLT_MAX : (1.0f / len_fact);
 
       /* Clamp the length factor, see: #62236. */
-      len_fact = MIN2(len_fact, 10.0f);
+      len_fact = std::min(len_fact, 10.0f);
 
       mul_v2_fl(no, ps->seam_bleed_px * len_fact);
 
diff --git a/source/blender/editors/sculpt_paint/sculpt_brush_types.cc b/source/blender/editors/sculpt_paint/sculpt_brush_types.cc
index 9d28a15550ac0dcd9c62af3264130121f73373c5..4e58d7a45b9ccfe5cfe757e12696c7d65f2ddae9 100644
--- a/source/blender/editors/sculpt_paint/sculpt_brush_types.cc
+++ b/source/blender/editors/sculpt_paint/sculpt_brush_types.cc
@@ -799,10 +799,10 @@ static void calc_clay_surface_task_cb(Object *ob,
     float plane_dist = dist_signed_to_plane_v3(vd.co, plane);
     float plane_dist_abs = fabsf(plane_dist);
     if (plane_dist > 0.0f) {
-      csd->plane_dist[0] = MIN2(csd->plane_dist[0], plane_dist_abs);
+      csd->plane_dist[0] = std::min(csd->plane_dist[0], plane_dist_abs);
     }
     else {
-      csd->plane_dist[1] = MIN2(csd->plane_dist[1], plane_dist_abs);
+      csd->plane_dist[1] = std::min(csd->plane_dist[1], plane_dist_abs);
     }
     BKE_pbvh_vertex_iter_end;
   }
diff --git a/source/blender/editors/space_file/file_draw.cc b/source/blender/editors/space_file/file_draw.cc
index 0fbe15aefe02c42d4ac24fa1a9e3b5a9ed1fffb6..b70e682fd3eaa9d866ec4581d8357886e482d762 100644
--- a/source/blender/editors/space_file/file_draw.cc
+++ b/source/blender/editors/space_file/file_draw.cc
@@ -311,7 +311,7 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, uiTooltipData *tip,
   }
 
   if (thumb && params->display != FILE_IMGDISPLAY) {
-    float scale = (96.0f * UI_SCALE_FAC) / float(MAX2(thumb->x, thumb->y));
+    float scale = (96.0f * UI_SCALE_FAC) / float(std::max(thumb->x, thumb->y));
     short size[2] = {short(float(thumb->x) * scale), short(float(thumb->y) * scale)};
     UI_tooltip_text_field_add(tip, {}, {}, UI_TIP_STYLE_SPACER, UI_TIP_LC_NORMAL);
     UI_tooltip_text_field_add(tip, {}, {}, UI_TIP_STYLE_SPACER, UI_TIP_LC_NORMAL);
@@ -1281,7 +1281,8 @@ void file_draw_list(const bContext *C, ARegion *region)
       if (do_drag) {
         const uiStyle *style = UI_style_get();
         const int str_width = UI_fontstyle_string_width(&style->widget, file->name);
-        const int drag_width = MIN2(str_width + icon_ofs, column_width - ATTRIBUTE_COLUMN_PADDING);
+        const int drag_width = std::min(str_width + icon_ofs,
+                                        int(column_width - ATTRIBUTE_COLUMN_PADDING));
         if (drag_width > 0) {
           uiBut *drag_but = uiDefBut(block,
                                      UI_BTYPE_LABEL,
diff --git a/source/blender/editors/space_file/file_ops.cc b/source/blender/editors/space_file/file_ops.cc
index ccd7ee7aaf06dfbef97e7af4c8d8ad4b511ee66a..80fb292f8f732c890a54b61b02eb012f6fdde5c8 100644
--- a/source/blender/editors/space_file/file_ops.cc
+++ b/source/blender/editors/space_file/file_ops.cc
@@ -792,7 +792,7 @@ static bool file_walk_select_selection_set(bContext *C,
 
   /* do the actual selection */
   if (fill) {
-    FileSelection sel = {MIN2(active, last_sel), MAX2(active, last_sel)};
+    FileSelection sel = {std::min(active, last_sel), std::max(active, last_sel)};
 
     /* fill selection between last and first selected file */
     filelist_entries_select_index_range_set(
diff --git a/source/blender/editors/space_file/fsmenu.cc b/source/blender/editors/space_file/fsmenu.cc
index 7af53b59189a1f9118dc0a9c018f007cfaca2ba0..1d1c324d46689cd20cc3b152dea8065a84875cad 100644
--- a/source/blender/editors/space_file/fsmenu.cc
+++ b/source/blender/editors/space_file/fsmenu.cc
@@ -6,6 +6,7 @@
  * \ingroup spfile
  */
 
+#include <algorithm>
 #include <cmath>
 #include <cstdio>
 #include <cstdlib>
@@ -163,7 +164,7 @@ static void fsmenu_entry_generate_name(FSMenuEntry *fsentry, char *name, size_t
     len += 1;
   }
 
-  BLI_strncpy(name, &fsentry->path[offset], MIN2(len, name_size));
+  BLI_strncpy(name, &fsentry->path[offset], std::min(size_t(len), name_size));
   if (!name[0]) {
     name[0] = '/';
     name[1] = '\0';
diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc
index 19bb4b8ff39fb173280101057989e55017aadcce..efee9e7b2600fdea1e4ab14014d53542c843a78e 100644
--- a/source/blender/editors/space_node/node_draw.cc
+++ b/source/blender/editors/space_node/node_draw.cc
@@ -998,7 +998,7 @@ static void node_update_hidden(bNode &node, uiBlock &block)
   }
 
   float hiddenrad = HIDDEN_RAD;
-  float tot = MAX2(totin, totout);
+  float tot = std::max(totin, totout);
   if (tot > 4) {
     hiddenrad += 5.0f * float(tot - 4);
   }
diff --git a/source/blender/editors/space_outliner/outliner_draw.cc b/source/blender/editors/space_outliner/outliner_draw.cc
index c71b3754188f7786fa23206fc84a7cef9ab2e7d5..19b544437a883fb265480e741765ab1c1ea205fe 100644
--- a/source/blender/editors/space_outliner/outliner_draw.cc
+++ b/source/blender/editors/space_outliner/outliner_draw.cc
@@ -91,7 +91,7 @@ static void outliner_tree_dimensions_impl(SpaceOutliner *space_outliner,
                                           int *height)
 {
   LISTBASE_FOREACH (TreeElement *, te, lb) {
-    *width = MAX2(*width, te->xend);
+    *width = std::max(*width, int(te->xend));
     if (height != nullptr) {
       *height += UI_UNIT_Y;
     }
diff --git a/source/blender/editors/space_outliner/outliner_tree.cc b/source/blender/editors/space_outliner/outliner_tree.cc
index 081d7dd5f8526c979752cfd646e906bbc68637c3..0a36afe996f3c62c0b4447e23d0a8b49e4d47466 100644
--- a/source/blender/editors/space_outliner/outliner_tree.cc
+++ b/source/blender/editors/space_outliner/outliner_tree.cc
@@ -6,6 +6,7 @@
  * \ingroup spoutliner
  */
 
+#include <algorithm>
 #include <cmath>
 #include <cstring>
 
@@ -691,7 +692,7 @@ static void outliner_restore_scrolling_position(SpaceOutliner *space_outliner,
       int ys_new = te_new->ys;
       int ys_old = focus->ys;
 
-      float y_move = MIN2(ys_new - ys_old, -v2d->cur.ymax);
+      float y_move = std::min(float(ys_new - ys_old), -v2d->cur.ymax);
       BLI_rctf_translate(&v2d->cur, 0, y_move);
     }
     else {
diff --git a/source/blender/editors/space_outliner/outliner_utils.cc b/source/blender/editors/space_outliner/outliner_utils.cc
index aec0803baccd3f080ba74820023f700242e1b40e..ac652558b66dd3620ae0bd732d6bf22176f2460b 100644
--- a/source/blender/editors/space_outliner/outliner_utils.cc
+++ b/source/blender/editors/space_outliner/outliner_utils.cc
@@ -6,6 +6,7 @@
  * \ingroup spoutliner
  */
 
+#include <algorithm>
 #include <cstring>
 
 #include "BLI_listbase.h"
@@ -421,7 +422,7 @@ void outliner_scroll_view(SpaceOutliner *space_outliner, ARegion *region, int de
 {
   int tree_width, tree_height;
   outliner_tree_dimensions(space_outliner, &tree_width, &tree_height);
-  int y_min = MIN2(region->v2d.cur.ymin, -tree_height);
+  int y_min = std::min(int(region->v2d.cur.ymin), -tree_height);
 
   region->v2d.cur.ymax += delta_y;
   region->v2d.cur.ymin += delta_y;
diff --git a/source/blender/editors/space_text/text_draw.cc b/source/blender/editors/space_text/text_draw.cc
index 0f41bbaef53d1aeb221997f1839ba19d7a66d095..7b57806d7bf26ca379aa054582a3fc6a53244e58 100644
--- a/source/blender/editors/space_text/text_draw.cc
+++ b/source/blender/editors/space_text/text_draw.cc
@@ -6,6 +6,8 @@
  * \ingroup sptext
  */
 
+#include <algorithm>
+
 #include "MEM_guardedalloc.h"
 
 #include "BLF_api.h"
@@ -271,7 +273,7 @@ void space_text_wrap_offset(
 
       while (chars--) {
         if (i + columns - start > max) {
-          end = MIN2(end, i);
+          end = std::min(end, i);
 
           if (chop && linep == linein && i >= cursin) {
             if (i == cursin) {
@@ -348,7 +350,7 @@ void space_text_wrap_offset_in_line(
 
     while (chars--) {
       if (i + columns - start > max) {
-        end = MIN2(end, i);
+        end = std::min(end, i);
 
         if (chop && i >= cursin) {
           if (i == cursin) {
@@ -939,7 +941,7 @@ static void calc_text_rcts(SpaceText *st, ARegion *region, rcti *scroll, rcti *b
       st, region, static_cast<TextLine *>(st->text->lines.first), st->text->curl);
   sell_off = space_text_get_span_wrap(
       st, region, static_cast<TextLine *>(st->text->lines.first), st->text->sell);
-  lhlstart = MIN2(curl_off, sell_off);
+  lhlstart = std::min(curl_off, sell_off);
   lhlend = std::max(curl_off, sell_off);
 
   if (ltexth > 0) {
@@ -1672,7 +1674,7 @@ void space_text_update_character_width(SpaceText *st)
 
   text_font_begin(&tdc);
   st->runtime->cwidth_px = BLF_fixed_width(tdc.font_id);
-  st->runtime->cwidth_px = MAX2(st->runtime->cwidth_px, char(1));
+  st->runtime->cwidth_px = std::max(st->runtime->cwidth_px, 1);
   text_font_end(&tdc);
 }
 
diff --git a/source/blender/editors/space_text/text_ops.cc b/source/blender/editors/space_text/text_ops.cc
index 47025682e07ca431396824c2fb97ea587df8a310..61fe9b96a450eb7c3d6cc2e0c44abf26d61c1f84 100644
--- a/source/blender/editors/space_text/text_ops.cc
+++ b/source/blender/editors/space_text/text_ops.cc
@@ -6,6 +6,7 @@
  * \ingroup sptext
  */
 
+#include <algorithm>
 #include <cerrno>
 #include <cstring>
 #include <sstream>
@@ -1790,7 +1791,7 @@ static int space_text_get_cursor_rel(
         curs = j;
       }
       if (i + columns - start > max) {
-        end = MIN2(end, i);
+        end = std::min(end, i);
 
         if (found) {
           /* exact cursor position was found, check if it's */
@@ -1985,7 +1986,7 @@ static void txt_wrap_move_bol(SpaceText *st, ARegion *region, const bool sel)
 
     while (chars--) {
       if (i + columns - start > max) {
-        end = MIN2(end, i);
+        end = std::min(end, i);
 
         *charp = endj;
 
@@ -2072,7 +2073,7 @@ static void txt_wrap_move_eol(SpaceText *st, ARegion *region, const bool sel)
 
     while (chars--) {
       if (i + columns - start > max) {
-        end = MIN2(end, i);
+        end = std::min(end, i);
 
         if (chop) {
           endj = BLI_str_find_prev_char_utf8((*linep)->line + j, (*linep)->line) - (*linep)->line;
@@ -3164,7 +3165,7 @@ static void space_text_cursor_set_to_pos_wrapped(
           curs = j;
         }
         if (i + columns - start > max) {
-          end = MIN2(end, i);
+          end = std::min(end, i);
 
           if (found) {
             /* exact cursor position was found, check if it's still on needed line
diff --git a/source/blender/editors/space_view3d/view3d_gizmo_navigate_type.cc b/source/blender/editors/space_view3d/view3d_gizmo_navigate_type.cc
index 1d81b75d8b750a5b9db596f6e7ed74101d51c9d4..8198f2b529991faf984166bde7b817be5f07d7ed 100644
--- a/source/blender/editors/space_view3d/view3d_gizmo_navigate_type.cc
+++ b/source/blender/editors/space_view3d/view3d_gizmo_navigate_type.cc
@@ -14,6 +14,8 @@
  * - matrix_offset: used to store the orientation.
  */
 
+#include <algorithm>
+
 #include "MEM_guardedalloc.h"
 
 #include "BLI_math_matrix.h"
@@ -225,12 +227,12 @@ static void gizmo_axis_draw(const bContext *C, wmGizmo *gz)
         if (is_aligned_front) {
           interp_v4_v4v4(
               negative_color, blender::float4{1.0f, 1.0f, 1.0f, 1.0f}, axis_color[axis], 0.5f);
-          negative_color[3] = MIN2(depth + 1, 1.0f);
+          negative_color[3] = std::min(depth + 1, 1.0f);
           outline_color = negative_color;
         }
         else {
           interp_v4_v4v4(negative_color, view_color, axis_color[axis], 0.25f);
-          negative_color[3] = MIN2(depth + 1, 1.0f);
+          negative_color[3] = std::min(depth + 1, 1.0f);
           inner_color = negative_color;
         }
       }
diff --git a/source/blender/editors/util/ed_util_imbuf.cc b/source/blender/editors/util/ed_util_imbuf.cc
index 7ec839f98b574f6b135b77f8f2c2db46ca95b921..ff93cc357ea80a3d35bc040ecdfdb57de065bdcb 100644
--- a/source/blender/editors/util/ed_util_imbuf.cc
+++ b/source/blender/editors/util/ed_util_imbuf.cc
@@ -6,6 +6,8 @@
  * \ingroup edutil
  */
 
+#include <algorithm>
+
 #include "MEM_guardedalloc.h"
 
 #include "BLI_math_vector_types.hh"
@@ -124,10 +126,10 @@ static void image_sample_rect_color_ubyte(const ImBuf *ibuf,
   }
   mul_v4_fl(r_col_linear, 1.0 / float(col_tot));
 
-  r_col[0] = MIN2(col_accum_ub[0] / col_tot, 255);
-  r_col[1] = MIN2(col_accum_ub[1] / col_tot, 255);
-  r_col[2] = MIN2(col_accum_ub[2] / col_tot, 255);
-  r_col[3] = MIN2(col_accum_ub[3] / col_tot, 255);
+  r_col[0] = std::min<uchar>(col_accum_ub[0] / col_tot, 255);
+  r_col[1] = std::min<uchar>(col_accum_ub[1] / col_tot, 255);
+  r_col[2] = std::min<uchar>(col_accum_ub[2] / col_tot, 255);
+  r_col[3] = std::min<uchar>(col_accum_ub[3] / col_tot, 255);
 }
 
 static void image_sample_rect_color_float(ImBuf *ibuf, const rcti *rect, float r_col[4])
diff --git a/source/blender/geometry/intern/reverse_uv_sampler.cc b/source/blender/geometry/intern/reverse_uv_sampler.cc
index c53ccb4cefe6819c161701865c89d7df4e0d47bb..fe1bb93d77c01cfc1619b30d9d21126f7bb2c2e1 100644
--- a/source/blender/geometry/intern/reverse_uv_sampler.cc
+++ b/source/blender/geometry/intern/reverse_uv_sampler.cc
@@ -2,6 +2,8 @@
  *
  * SPDX-License-Identifier: GPL-2.0-or-later */
 
+#include <algorithm>
+
 #include "GEO_reverse_uv_sampler.hh"
 
 #include "BLI_math_geom.h"
@@ -72,7 +74,7 @@ ReverseUVSampler::Result ReverseUVSampler::sample(const float2 &query_uv) const
     const float x_dist = std::max(-bary_weights.x, bary_weights.x - 1.0f);
     const float y_dist = std::max(-bary_weights.y, bary_weights.y - 1.0f);
     const float z_dist = std::max(-bary_weights.z, bary_weights.z - 1.0f);
-    const float dist = MAX3(x_dist, y_dist, z_dist);
+    const float dist = std::max({x_dist, y_dist, z_dist});
 
     if (dist <= 0.0f && best_dist <= 0.0f) {
       const float worse_dist = std::max(dist, best_dist);
diff --git a/source/blender/gpencil_modifiers_legacy/intern/MOD_gpencil_legacy_build.cc b/source/blender/gpencil_modifiers_legacy/intern/MOD_gpencil_legacy_build.cc
index 0314cf68d0c54a0d422df490d02f02db96815736..6715e3a330e147dde6401ce9c8b432ab1276c962 100644
--- a/source/blender/gpencil_modifiers_legacy/intern/MOD_gpencil_legacy_build.cc
+++ b/source/blender/gpencil_modifiers_legacy/intern/MOD_gpencil_legacy_build.cc
@@ -6,7 +6,7 @@
  * \ingroup modifiers
  */
 
-#include <algorithm> /* For `min/max`. */
+#include <algorithm>
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
@@ -809,7 +809,7 @@ static void generate_geometry(GpencilModifierData *md,
 
     if (gpf->next) {
       /* Use the next frame or upper bound as end frame, whichever is lower/closer */
-      end_frame = MIN2(end_frame, gpf->next->framenum);
+      end_frame = std::min(end_frame, float(gpf->next->framenum));
     }
 
     /* Early exit if current frame is outside start/end bounds */
diff --git a/source/blender/gpencil_modifiers_legacy/intern/MOD_gpencil_legacy_dash.cc b/source/blender/gpencil_modifiers_legacy/intern/MOD_gpencil_legacy_dash.cc
index 256366fb4adabcb6d952bf557e4f017abfa6241f..ba838550d5fe3aed41836fba1bfd5bddfcd4725f 100644
--- a/source/blender/gpencil_modifiers_legacy/intern/MOD_gpencil_legacy_dash.cc
+++ b/source/blender/gpencil_modifiers_legacy/intern/MOD_gpencil_legacy_dash.cc
@@ -6,6 +6,7 @@
  * \ingroup modifiers
  */
 
+#include <algorithm>
 #include <cstdio>
 #include <cstring>
 
@@ -143,7 +144,7 @@ static bool stroke_dash(const bGPDstroke *gps,
       continue;
     }
 
-    const int size = MIN2(gps->totpoints - new_stroke_offset, seg);
+    const int size = std::min(gps->totpoints - new_stroke_offset, seg);
     if (size == 0) {
       continue;
     }
diff --git a/source/blender/gpencil_modifiers_legacy/intern/MOD_gpencil_legacy_weight_proximity.cc b/source/blender/gpencil_modifiers_legacy/intern/MOD_gpencil_legacy_weight_proximity.cc
index e7546fd619ed1f5972565c555851064586585f96..32ce86ae53bdc50e1ee21c1a5cc0bab008158c7a 100644
--- a/source/blender/gpencil_modifiers_legacy/intern/MOD_gpencil_legacy_weight_proximity.cc
+++ b/source/blender/gpencil_modifiers_legacy/intern/MOD_gpencil_legacy_weight_proximity.cc
@@ -108,8 +108,8 @@ static void deform_stroke(GpencilModifierData *md,
     return;
   }
 
-  const float dist_max = MAX2(mmd->dist_start, mmd->dist_end);
-  const float dist_min = MIN2(mmd->dist_start, mmd->dist_end);
+  const float dist_max = std::max(mmd->dist_start, mmd->dist_end);
+  const float dist_min = std::min(mmd->dist_start, mmd->dist_end);
   const int target_def_nr = BKE_object_defgroup_name_index(ob, mmd->target_vgname);
 
   if (target_def_nr == -1) {
diff --git a/source/blender/gpencil_modifiers_legacy/intern/lineart/MOD_lineart.h b/source/blender/gpencil_modifiers_legacy/intern/lineart/MOD_lineart.h
index 891b4c6431e7db91be64530451d0370ded2ccd7f..e9882aed214f1a62c40cb91a40b8f841e02196cb 100644
--- a/source/blender/gpencil_modifiers_legacy/intern/lineart/MOD_lineart.h
+++ b/source/blender/gpencil_modifiers_legacy/intern/lineart/MOD_lineart.h
@@ -13,6 +13,7 @@
 #include "BLI_math_vector.h"
 #include "BLI_threads.h"
 
+#include <algorithm>
 #include <math.h>
 
 #ifdef __cplusplus
@@ -743,7 +744,7 @@ BLI_INLINE int lineart_intersect_seg_seg(const double a1[2],
 
   if (LRT_DOUBLE_CLOSE_ENOUGH(b1[0], b2[0])) {
     y = interpd(a2[1], a1[1], ratio);
-    if (y > MAX2(b1[1], b2[1]) || y < MIN2(b1[1], b2[1])) {
+    if (y > std::max(b1[1], b2[1]) || y < std::min(b1[1], b2[1])) {
       return 0;
     }
   }
diff --git a/source/blender/gpencil_modifiers_legacy/intern/lineart/lineart_chain.cc b/source/blender/gpencil_modifiers_legacy/intern/lineart/lineart_chain.cc
index 3e1e72aa9da4af5a9db69ec90c8ede6e19682169..7028b7bf092f265cdd2a2a41b1819939b4cb03a2 100644
--- a/source/blender/gpencil_modifiers_legacy/intern/lineart/lineart_chain.cc
+++ b/source/blender/gpencil_modifiers_legacy/intern/lineart/lineart_chain.cc
@@ -1372,7 +1372,7 @@ void MOD_lineart_chain_offset_towards_camera(LineartData *ld, float dist, bool u
         sub_v3_v3v3(dir, cam, eci->gpos);
         float orig_len = len_v3(dir);
         normalize_v3(dir);
-        mul_v3_fl(dir, MIN2(dist, orig_len - ld->conf.near_clip));
+        mul_v3_fl(dir, std::min<float>(dist, orig_len - ld->conf.near_clip));
         add_v3_v3(eci->gpos, dir);
       }
     }
diff --git a/source/blender/gpencil_modifiers_legacy/intern/lineart/lineart_cpu.cc b/source/blender/gpencil_modifiers_legacy/intern/lineart/lineart_cpu.cc
index 35e8ce7e168be0bf37254db8e5d87111a2577c12..533cb576dc5f821fa2058b178b1514fd0680c2f7 100644
--- a/source/blender/gpencil_modifiers_legacy/intern/lineart/lineart_cpu.cc
+++ b/source/blender/gpencil_modifiers_legacy/intern/lineart/lineart_cpu.cc
@@ -6,6 +6,8 @@
  * \ingroup editors
  */
 
+#include <algorithm>
+
 #include "MOD_gpencil_legacy_lineart.h"
 #include "MOD_lineart.h"
 
@@ -344,7 +346,7 @@ void lineart_edge_cut(LineartData *ld,
       continue;
     }
 
-    min_occ = MIN2(min_occ, seg->occlusion);
+    min_occ = std::min<int8_t>(min_occ, seg->occlusion);
 
     prev_seg = seg;
   }
@@ -2843,11 +2845,11 @@ static bool lineart_triangle_edge_image_space_occlusion(const LineartTriangle *t
          *FBC1 = tri->v[1]->fbcoord, *FBC2 = tri->v[2]->fbcoord;
 
   /* Overlapping not possible, return early. */
-  if ((MAX3(FBC0[0], FBC1[0], FBC2[0]) < MIN2(LFBC[0], RFBC[0])) ||
-      (MIN3(FBC0[0], FBC1[0], FBC2[0]) > MAX2(LFBC[0], RFBC[0])) ||
-      (MAX3(FBC0[1], FBC1[1], FBC2[1]) < MIN2(LFBC[1], RFBC[1])) ||
-      (MIN3(FBC0[1], FBC1[1], FBC2[1]) > MAX2(LFBC[1], RFBC[1])) ||
-      (MIN3(FBC0[3], FBC1[3], FBC2[3]) > MAX2(LFBC[3], RFBC[3])))
+  if ((std::max({FBC0[0], FBC1[0], FBC2[0]}) < std::min(LFBC[0], RFBC[0])) ||
+      (std::min({FBC0[0], FBC1[0], FBC2[0]}) > std::max(LFBC[0], RFBC[0])) ||
+      (std::max({FBC0[1], FBC1[1], FBC2[1]}) < std::min(LFBC[1], RFBC[1])) ||
+      (std::min({FBC0[1], FBC1[1], FBC2[1]}) > std::max(LFBC[1], RFBC[1])) ||
+      (std::min({FBC0[3], FBC1[3], FBC2[3]}) > std::max(LFBC[3], RFBC[3])))
   {
     return false;
   }
@@ -3067,8 +3069,8 @@ static bool lineart_triangle_edge_image_space_occlusion(const LineartTriangle *t
 
   /* Determine the start and end point of image space cut on a line. */
   if (dot_1f <= 0 && dot_2f <= 0 && (dot_v1 || dot_v2)) {
-    *from = MAX2(0, cross_ratios[cross_v1]);
-    *to = MIN2(1, cross_ratios[cross_v2]);
+    *from = std::max(0.0, cross_ratios[cross_v1]);
+    *to = std::min(1.0, cross_ratios[cross_v2]);
     if (*from >= *to) {
       return false;
     }
@@ -3076,14 +3078,14 @@ static bool lineart_triangle_edge_image_space_occlusion(const LineartTriangle *t
   }
   if (dot_1f >= 0 && dot_2f <= 0 && (dot_v1 || dot_v2)) {
     *from = std::max(cut, cross_ratios[cross_v1]);
-    *to = MIN2(1, cross_ratios[cross_v2]);
+    *to = std::min(1.0, cross_ratios[cross_v2]);
     if (*from >= *to) {
       return false;
     }
     return true;
   }
   if (dot_1f <= 0 && dot_2f >= 0 && (dot_v1 || dot_v2)) {
-    *from = MAX2(0, cross_ratios[cross_v1]);
+    *from = std::max(0.0, cross_ratios[cross_v1]);
     *to = std::min(cut, cross_ratios[cross_v2]);
     if (*from >= *to) {
       return false;
@@ -3346,7 +3348,7 @@ static bool lineart_schedule_new_triangle_task(LineartIsecThread *th)
 
   while (remaining > 0 && eln) {
     int remaining_this_eln = eln->element_count - ld->isect_scheduled_up_to_index;
-    int added_count = MIN2(remaining, remaining_this_eln);
+    int added_count = std::min(remaining, remaining_this_eln);
     remaining -= added_count;
     if (remaining || added_count == remaining_this_eln) {
       eln = eln->next;
@@ -3441,12 +3443,12 @@ static void lineart_triangle_intersect_in_bounding_area(LineartTriangle *tri,
            *RG2 = testing_triangle->v[2]->gloc;
 
     /* Bounding box not overlapping or triangles share edges, not potential of intersecting. */
-    if ((MIN3(G0[2], G1[2], G2[2]) > MAX3(RG0[2], RG1[2], RG2[2])) ||
-        (MAX3(G0[2], G1[2], G2[2]) < MIN3(RG0[2], RG1[2], RG2[2])) ||
-        (MIN3(G0[0], G1[0], G2[0]) > MAX3(RG0[0], RG1[0], RG2[0])) ||
-        (MAX3(G0[0], G1[0], G2[0]) < MIN3(RG0[0], RG1[0], RG2[0])) ||
-        (MIN3(G0[1], G1[1], G2[1]) > MAX3(RG0[1], RG1[1], RG2[1])) ||
-        (MAX3(G0[1], G1[1], G2[1]) < MIN3(RG0[1], RG1[1], RG2[1])) ||
+    if ((std::min({G0[2], G1[2], G2[2]}) > std::max({RG0[2], RG1[2], RG2[2]})) ||
+        (std::max({G0[2], G1[2], G2[2]}) < std::min({RG0[2], RG1[2], RG2[2]})) ||
+        (std::min({G0[0], G1[0], G2[0]}) > std::max({RG0[0], RG1[0], RG2[0]})) ||
+        (std::max({G0[0], G1[0], G2[0]}) < std::min({RG0[0], RG1[0], RG2[0]})) ||
+        (std::min({G0[1], G1[1], G2[1]}) > std::max({RG0[1], RG1[1], RG2[1]})) ||
+        (std::max({G0[1], G1[1], G2[1]}) < std::min({RG0[1], RG1[1], RG2[1]})) ||
         lineart_triangle_share_edge(tri, testing_triangle))
     {
       continue;
@@ -4029,10 +4031,10 @@ static void lineart_bounding_area_split(LineartData *ld,
     LineartTriangle *tri = root->linked_triangles[i];
 
     double b[4];
-    b[0] = MIN3(tri->v[0]->fbcoord[0], tri->v[1]->fbcoord[0], tri->v[2]->fbcoord[0]);
-    b[1] = MAX3(tri->v[0]->fbcoord[0], tri->v[1]->fbcoord[0], tri->v[2]->fbcoord[0]);
-    b[2] = MAX3(tri->v[0]->fbcoord[1], tri->v[1]->fbcoord[1], tri->v[2]->fbcoord[1]);
-    b[3] = MIN3(tri->v[0]->fbcoord[1], tri->v[1]->fbcoord[1], tri->v[2]->fbcoord[1]);
+    b[0] = std::min({tri->v[0]->fbcoord[0], tri->v[1]->fbcoord[0], tri->v[2]->fbcoord[0]});
+    b[1] = std::max({tri->v[0]->fbcoord[0], tri->v[1]->fbcoord[0], tri->v[2]->fbcoord[0]});
+    b[2] = std::max({tri->v[0]->fbcoord[1], tri->v[1]->fbcoord[1], tri->v[2]->fbcoord[1]});
+    b[3] = std::min({tri->v[0]->fbcoord[1], tri->v[1]->fbcoord[1], tri->v[2]->fbcoord[1]});
 
     /* Re-link triangles into child tiles, not doing intersection lines during this because this
      * batch of triangles are all tested with each other for intersections. */
@@ -4068,8 +4070,9 @@ static bool lineart_bounding_area_edge_intersect(LineartData * /*fb*/,
   double converted[4];
   double c1, c;
 
-  if (((converted[0] = ba->l) > MAX2(l[0], r[0])) || ((converted[1] = ba->r) < MIN2(l[0], r[0])) ||
-      ((converted[2] = ba->b) > MAX2(l[1], r[1])) ||
+  if (((converted[0] = ba->l) > std::max(l[0], r[0])) ||
+      ((converted[1] = ba->r) < std::min(l[0], r[0])) ||
+      ((converted[2] = ba->b) > std::max(l[1], r[1])) ||
       ((converted[3] = ba->u) < std::min(l[1], r[1])))
   {
     return false;
@@ -4177,10 +4180,10 @@ static void lineart_bounding_area_link_triangle(LineartData *ld,
     double *B1 = l_r_u_b;
     double b[4];
     if (!l_r_u_b) {
-      b[0] = MIN3(tri->v[0]->fbcoord[0], tri->v[1]->fbcoord[0], tri->v[2]->fbcoord[0]);
-      b[1] = MAX3(tri->v[0]->fbcoord[0], tri->v[1]->fbcoord[0], tri->v[2]->fbcoord[0]);
-      b[2] = MAX3(tri->v[0]->fbcoord[1], tri->v[1]->fbcoord[1], tri->v[2]->fbcoord[1]);
-      b[3] = MIN3(tri->v[0]->fbcoord[1], tri->v[1]->fbcoord[1], tri->v[2]->fbcoord[1]);
+      b[0] = std::min({tri->v[0]->fbcoord[0], tri->v[1]->fbcoord[0], tri->v[2]->fbcoord[0]});
+      b[1] = std::max({tri->v[0]->fbcoord[0], tri->v[1]->fbcoord[0], tri->v[2]->fbcoord[0]});
+      b[2] = std::max({tri->v[0]->fbcoord[1], tri->v[1]->fbcoord[1], tri->v[2]->fbcoord[1]});
+      b[3] = std::min({tri->v[0]->fbcoord[1], tri->v[1]->fbcoord[1], tri->v[2]->fbcoord[1]});
       B1 = b;
     }
     for (int iba = 0; iba < 4; iba++) {
@@ -4409,10 +4412,10 @@ static bool lineart_get_triangle_bounding_areas(
     return false;
   }
 
-  b[0] = MIN3(tri->v[0]->fbcoord[0], tri->v[1]->fbcoord[0], tri->v[2]->fbcoord[0]);
-  b[1] = MAX3(tri->v[0]->fbcoord[0], tri->v[1]->fbcoord[0], tri->v[2]->fbcoord[0]);
-  b[2] = MIN3(tri->v[0]->fbcoord[1], tri->v[1]->fbcoord[1], tri->v[2]->fbcoord[1]);
-  b[3] = MAX3(tri->v[0]->fbcoord[1], tri->v[1]->fbcoord[1], tri->v[2]->fbcoord[1]);
+  b[0] = std::min({tri->v[0]->fbcoord[0], tri->v[1]->fbcoord[0], tri->v[2]->fbcoord[0]});
+  b[1] = std::max({tri->v[0]->fbcoord[0], tri->v[1]->fbcoord[0], tri->v[2]->fbcoord[0]});
+  b[2] = std::min({tri->v[0]->fbcoord[1], tri->v[1]->fbcoord[1], tri->v[2]->fbcoord[1]});
+  b[3] = std::max({tri->v[0]->fbcoord[1], tri->v[1]->fbcoord[1], tri->v[2]->fbcoord[1]});
 
   if (b[0] > 1 || b[1] < -1 || b[2] > 1 || b[3] < -1) {
     return false;
@@ -4453,9 +4456,9 @@ static bool lineart_get_edge_bounding_areas(
     return false;
   }
 
-  b[0] = MIN2(e->v1->fbcoord[0], e->v2->fbcoord[0]);
+  b[0] = std::min(e->v1->fbcoord[0], e->v2->fbcoord[0]);
   b[1] = std::max(e->v1->fbcoord[0], e->v2->fbcoord[0]);
-  b[2] = MIN2(e->v1->fbcoord[1], e->v2->fbcoord[1]);
+  b[2] = std::min(e->v1->fbcoord[1], e->v2->fbcoord[1]);
   b[3] = std::max(e->v1->fbcoord[1], e->v2->fbcoord[1]);
 
   if (b[0] > 1 || b[1] < -1 || b[2] > 1 || b[3] < -1) {
@@ -4799,7 +4802,7 @@ LineartBoundingArea *lineart_bounding_area_next(LineartBoundingArea *self,
       ux = x + (uy - y) / k;
       r1 = ratiod(fbcoord1[0], fbcoord2[0], rx);
       r2 = ratiod(fbcoord1[0], fbcoord2[0], ux);
-      if (MIN2(r1, r2) > 1) {
+      if (std::min(r1, r2) > 1) {
         return nullptr;
       }
 
@@ -4832,7 +4835,7 @@ LineartBoundingArea *lineart_bounding_area_next(LineartBoundingArea *self,
       bx = x + (by - y) / k;
       r1 = ratiod(fbcoord1[0], fbcoord2[0], rx);
       r2 = ratiod(fbcoord1[0], fbcoord2[0], bx);
-      if (MIN2(r1, r2) > 1) {
+      if (std::min(r1, r2) > 1) {
         return nullptr;
       }
       if (r1 <= r2) {
@@ -4884,7 +4887,7 @@ LineartBoundingArea *lineart_bounding_area_next(LineartBoundingArea *self,
       ux = x + (uy - y) / k;
       r1 = ratiod(fbcoord1[0], fbcoord2[0], lx);
       r2 = ratiod(fbcoord1[0], fbcoord2[0], ux);
-      if (MIN2(r1, r2) > 1) {
+      if (std::min(r1, r2) > 1) {
         return nullptr;
       }
       if (r1 <= r2) {
@@ -4915,7 +4918,7 @@ LineartBoundingArea *lineart_bounding_area_next(LineartBoundingArea *self,
       bx = x + (by - y) / k;
       r1 = ratiod(fbcoord1[0], fbcoord2[0], lx);
       r2 = ratiod(fbcoord1[0], fbcoord2[0], bx);
-      if (MIN2(r1, r2) > 1) {
+      if (std::min(r1, r2) > 1) {
         return nullptr;
       }
       if (r1 <= r2) {
diff --git a/source/blender/gpencil_modifiers_legacy/intern/lineart/lineart_shadow.cc b/source/blender/gpencil_modifiers_legacy/intern/lineart/lineart_shadow.cc
index eec9a8594e8477fcb8748b7b978cc87ef89e0020..8382603be90a7b4cade7f30d50718164e28597d4 100644
--- a/source/blender/gpencil_modifiers_legacy/intern/lineart/lineart_shadow.cc
+++ b/source/blender/gpencil_modifiers_legacy/intern/lineart/lineart_shadow.cc
@@ -736,10 +736,10 @@ static bool lineart_shadow_cast_onto_triangle(LineartData *ld,
   /* Bound box check. Because we have already done occlusion in the shadow camera, so any visual
    * intersection found in this function must mean that the triangle is behind the given line so it
    * will always project a shadow, hence no need to do depth bound-box check. */
-  if ((MAX3(FBC0[0], FBC1[0], FBC2[0]) < MIN2(LFBC[0], RFBC[0])) ||
-      (MIN3(FBC0[0], FBC1[0], FBC2[0]) > MAX2(LFBC[0], RFBC[0])) ||
-      (MAX3(FBC0[1], FBC1[1], FBC2[1]) < MIN2(LFBC[1], RFBC[1])) ||
-      (MIN3(FBC0[1], FBC1[1], FBC2[1]) > MAX2(LFBC[1], RFBC[1])))
+  if ((std::max({FBC0[0], FBC1[0], FBC2[0]}) < std::min(LFBC[0], RFBC[0])) ||
+      (std::min({FBC0[0], FBC1[0], FBC2[0]}) > std::max(LFBC[0], RFBC[0])) ||
+      (std::max({FBC0[1], FBC1[1], FBC2[1]}) < std::min(LFBC[1], RFBC[1])) ||
+      (std::min({FBC0[1], FBC1[1], FBC2[1]}) > std::max(LFBC[1], RFBC[1])))
   {
     return false;
   }
diff --git a/source/blender/gpu/intern/gpu_index_buffer.cc b/source/blender/gpu/intern/gpu_index_buffer.cc
index 4b3103dbbe1b424e168c072d1cfd8c5bb936b6cc..162f7cc3f2082cd3e3e94b7f9b6cb0ea66ab9a0a 100644
--- a/source/blender/gpu/intern/gpu_index_buffer.cc
+++ b/source/blender/gpu/intern/gpu_index_buffer.cc
@@ -186,8 +186,8 @@ void GPU_indexbuf_set_line_verts(GPUIndexBufBuilder *builder, uint elem, uint v1
   uint idx = elem * 2;
   builder->data[idx++] = v1;
   builder->data[idx++] = v2;
-  builder->index_min = MIN3(builder->index_min, v1, v2);
-  builder->index_max = MAX3(builder->index_max, v1, v2);
+  builder->index_min = std::min({builder->index_min, v1, v2});
+  builder->index_max = std::max({builder->index_max, v1, v2});
   builder->index_len = std::max(builder->index_len, idx);
 }
 
@@ -204,8 +204,8 @@ void GPU_indexbuf_set_tri_verts(GPUIndexBufBuilder *builder, uint elem, uint v1,
   builder->data[idx++] = v2;
   builder->data[idx++] = v3;
 
-  builder->index_min = MIN4(builder->index_min, v1, v2, v3);
-  builder->index_max = MAX4(builder->index_max, v1, v2, v3);
+  builder->index_min = std::min({builder->index_min, v1, v2, v3});
+  builder->index_max = std::max({builder->index_max, v1, v2, v3});
   builder->index_len = std::max(builder->index_len, idx);
 }
 
@@ -390,7 +390,7 @@ void IndexBuf::squeeze_indices_short(uint min_idx,
                                  0xFFFFu :
                                  (max_idx - min_idx);
     for (uint i = 0; i < index_len_; i++) {
-      ushort_idx[i] = uint16_t(MIN2(clamp_max_idx, uint_idx[i] - min_idx));
+      ushort_idx[i] = std::min<uint16_t>(clamp_max_idx, uint_idx[i] - min_idx);
     }
   }
   else {
diff --git a/source/blender/gpu/intern/gpu_material.cc b/source/blender/gpu/intern/gpu_material.cc
index 99700c62a8e55d80e2eb1f49f7eaf49277e7ef2d..4d4c8652f7561f22f5625a66419645eeb8e90ec8 100644
--- a/source/blender/gpu/intern/gpu_material.cc
+++ b/source/blender/gpu/intern/gpu_material.cc
@@ -8,6 +8,7 @@
  * Manages materials, lights and textures.
  */
 
+#include <algorithm>
 #include <cmath>
 #include <cstring>
 
@@ -433,8 +434,8 @@ static void compute_sss_kernel(GPUSssKernelData *kd, const float radii[3], int s
 {
   float rad[3];
   /* Minimum radius */
-  rad[0] = MAX2(radii[0], 1e-15f);
-  rad[1] = MAX2(radii[1], 1e-15f);
+  rad[0] = std::max(radii[0], 1e-15f);
+  rad[1] = std::max(radii[1], 1e-15f);
   rad[2] = std::max(radii[2], 1e-15f);
 
   kd->avg_inv_radius = 3.0f / (rad[0] + rad[1] + rad[2]);
@@ -448,7 +449,7 @@ static void compute_sss_kernel(GPUSssKernelData *kd, const float radii[3], int s
   /* XXX 0.6f Out of nowhere to match cycles! Empirical! Can be tweak better. */
   mul_v3_v3fl(d, l, 0.6f / s);
   mul_v3_v3fl(rad, d, BURLEY_TRUNCATE);
-  kd->max_radius = MAX3(rad[0], rad[1], rad[2]);
+  kd->max_radius = std::max({rad[0], rad[1], rad[2]});
 
   copy_v3_v3(kd->param, d);
 
diff --git a/source/blender/ikplugin/intern/iksolver_plugin.cc b/source/blender/ikplugin/intern/iksolver_plugin.cc
index 9f573b58356f8c21a5433f0a0228802c84e077ca..4a658cffa6238189ab2df2368615e38c44774f42 100644
--- a/source/blender/ikplugin/intern/iksolver_plugin.cc
+++ b/source/blender/ikplugin/intern/iksolver_plugin.cc
@@ -6,6 +6,8 @@
  * \ingroup ikplugin
  */
 
+#include <algorithm>
+
 #include "MEM_guardedalloc.h"
 
 #include "BIK_api.h"
@@ -142,11 +144,11 @@ static void initialize_posetree(Object * /*ob*/, bPoseChannel *pchan_tip)
       BLI_addtail(&pchan_root->iktree, tree);
     }
     else {
-      tree->iterations = MAX2(data->iterations, tree->iterations);
+      tree->iterations = std::max<int>(data->iterations, tree->iterations);
       tree->stretch = tree->stretch && !(data->flag & CONSTRAINT_IK_STRETCH);
 
       /* Skip common pose channels and add remaining. */
-      const int size = MIN2(segcount, tree->totchannel);
+      const int size = std::min(segcount, tree->totchannel);
       int a, t;
       a = t = 0;
       while (a < size && t < tree->totchannel) {
diff --git a/source/blender/ikplugin/intern/itasc_plugin.cc b/source/blender/ikplugin/intern/itasc_plugin.cc
index 5ec04ac7fd447ac342eccaadc9a253e293521d92..545ddc379bc458b120bd1d7bf51c2f967e18136e 100644
--- a/source/blender/ikplugin/intern/itasc_plugin.cc
+++ b/source/blender/ikplugin/intern/itasc_plugin.cc
@@ -6,6 +6,7 @@
  * \ingroup ikplugin
  */
 
+#include <algorithm>
 #include <cmath>
 #include <cstdlib>
 #include <cstring>
@@ -299,11 +300,11 @@ static int initialize_chain(Object *ob, bPoseChannel *pchan_tip, bConstraint *co
     treecount = 1;
   }
   else {
-    tree->iterations = MAX2(data->iterations, tree->iterations);
+    tree->iterations = std::max<int>(data->iterations, tree->iterations);
     tree->stretch = tree->stretch && !(data->flag & CONSTRAINT_IK_STRETCH);
 
     /* Skip common pose channels and add remaining. */
-    size = MIN2(segcount, tree->totchannel);
+    size = std::min(segcount, tree->totchannel);
     a = t = 0;
     while (a < size && t < tree->totchannel) {
       /* locate first matching channel */
diff --git a/source/blender/imbuf/CMakeLists.txt b/source/blender/imbuf/CMakeLists.txt
index 69facb59ea67260b2a195a773715f2cd1f1342a7..82094cfcaf7894b286aeb850393b82313b33c63c 100644
--- a/source/blender/imbuf/CMakeLists.txt
+++ b/source/blender/imbuf/CMakeLists.txt
@@ -191,6 +191,10 @@ if(WIN32)
   )
 endif()
 
+if(WIN32)
+  add_definitions(-DNOMINMAX)
+endif()
+
 # no need to compile object files for inline headers.
 set_source_files_properties(
   intern/colormanagement_inline.cc
diff --git a/source/blender/imbuf/intern/anim_movie.cc b/source/blender/imbuf/intern/anim_movie.cc
index 330a9d785239c9d8562332831ab182ac16560cff..2a1e4b871771d497f9e77c4dba3ea5588d8a8fdf 100644
--- a/source/blender/imbuf/intern/anim_movie.cc
+++ b/source/blender/imbuf/intern/anim_movie.cc
@@ -1050,7 +1050,7 @@ static int match_format(const char *name, AVFormatContext *pFormatCtx)
 
   namelen = strlen(name);
   while ((p = strchr(names, ','))) {
-    len = MAX2(p - names, namelen);
+    len = std::max(int(p - names), namelen);
     if (!BLI_strncasecmp(name, names, len)) {
       return 1;
     }
@@ -1174,7 +1174,7 @@ static int ffmpeg_generic_seek_workaround(anim *anim,
   /* Step backward frame by frame until we find the key frame we are looking for. */
   while (current_pts != 0) {
     current_pts = *requested_pts - int64_t(round(offset * ffmpeg_steps_per_frame_get(anim)));
-    current_pts = MAX2(current_pts, 0);
+    current_pts = std::max(current_pts, int64_t(0));
 
     /* Seek to timestamp. */
     if (av_seek_frame(anim->pFormatCtx, anim->videoStream, current_pts, AVSEEK_FLAG_BACKWARD) < 0)
diff --git a/source/blender/imbuf/intern/jpeg.cc b/source/blender/imbuf/intern/jpeg.cc
index 82d8f43322fec980dfd829e619f3c6b5dab019e6..61a4b91bcb23514231e93ff0d3a9a3f9da512776 100644
--- a/source/blender/imbuf/intern/jpeg.cc
+++ b/source/blender/imbuf/intern/jpeg.cc
@@ -7,6 +7,7 @@
  */
 
 /* This little block needed for linking to Blender... */
+#include <algorithm>
 #include <csetjmp>
 #include <cstdio>
 
@@ -428,7 +429,7 @@ static ImBuf *ibJpegImageFromCinfo(
       }
 
       ibuf->ftype = IMB_FTYPE_JPG;
-      ibuf->foptions.quality = MIN2(ibuf_quality, 100);
+      ibuf->foptions.quality = std::min<char>(ibuf_quality, 100);
     }
     jpeg_destroy((j_common_ptr)cinfo);
   }
diff --git a/source/blender/imbuf/intern/openexr/openexr_api.cpp b/source/blender/imbuf/intern/openexr/openexr_api.cpp
index 7823950f49ea326e8c48f2ba7f845248f6f3f7f0..e6f627c096c82cfacb395a9c8fc36494042d937f 100644
--- a/source/blender/imbuf/intern/openexr/openexr_api.cpp
+++ b/source/blender/imbuf/intern/openexr/openexr_api.cpp
@@ -2260,7 +2260,7 @@ ImBuf *imb_load_filepath_thumbnail_openexr(const char *filepath,
 
       for (int w = 0; w < dest_w; w++) {
         /* For each destination pixel find single corresponding source pixel. */
-        int source_x = int(MIN2((w / scale_factor), dw.max.x - 1));
+        int source_x = int(std::min<int>((w / scale_factor), dw.max.x - 1));
         float *dest_px = &ibuf->float_buffer.data[(h * dest_w + w) * 4];
         dest_px[0] = pixels[source_x].r;
         dest_px[1] = pixels[source_x].g;
diff --git a/source/blender/imbuf/intern/stereoimbuf.cc b/source/blender/imbuf/intern/stereoimbuf.cc
index 114aac9747a6360c3ba2097239d8efe4b1200888..8aaf1b835ee14f32390635faaaf2f709a42ad397 100644
--- a/source/blender/imbuf/intern/stereoimbuf.cc
+++ b/source/blender/imbuf/intern/stereoimbuf.cc
@@ -6,6 +6,7 @@
  * \ingroup imbuf
  */
 
+#include <algorithm>
 #include <cstddef>
 
 #include "IMB_imbuf.hh"
@@ -100,7 +101,7 @@ static void imb_stereo3d_write_anaglyph(const Stereo3DData *s3d, enum eStereo3dA
           to[0] = from[r][0];
           to[1] = from[g][1];
           to[2] = from[b][2];
-          to[3] = MAX2(from[0][3], from[1][3]);
+          to[3] = std::max(from[0][3], from[1][3]);
         }
       }
     }
diff --git a/source/blender/imbuf/intern/thumbs.cc b/source/blender/imbuf/intern/thumbs.cc
index d5ccdba87b613e26b2c1ac0ad3ecdb6ef16f2a52..4aa16b373b9387ae956848376163808fb2e2735b 100644
--- a/source/blender/imbuf/intern/thumbs.cc
+++ b/source/blender/imbuf/intern/thumbs.cc
@@ -6,6 +6,7 @@
  * \ingroup imbuf
  */
 
+#include <algorithm>
 #include <cstdio>
 #include <cstdlib>
 
@@ -412,10 +413,10 @@ static ImBuf *thumb_create_ex(const char *file_path,
       }
 
       if (img->x > tsize || img->y > tsize) {
-        float scale = MIN2(float(tsize) / float(img->x), float(tsize) / float(img->y));
+        float scale = std::min(float(tsize) / float(img->x), float(tsize) / float(img->y));
         /* Scaling down must never assign zero width/height, see: #89868. */
-        short ex = MAX2(1, short(img->x * scale));
-        short ey = MAX2(1, short(img->y * scale));
+        short ex = std::max(short(1), short(img->x * scale));
+        short ey = std::max(short(1), short(img->y * scale));
         /* Save some time by only scaling byte buffer. */
         if (img->float_buffer.data) {
           if (img->byte_buffer.data == nullptr) {
diff --git a/source/blender/io/gpencil/intern/gpencil_io_export_pdf.cc b/source/blender/io/gpencil/intern/gpencil_io_export_pdf.cc
index a9b884ee3e6d2aef759ab3f1c81dc558710d1ab3..686c82dfadcb6bcc539a41cc6ea70d02509e0951 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_export_pdf.cc
+++ b/source/blender/io/gpencil/intern/gpencil_io_export_pdf.cc
@@ -6,6 +6,8 @@
  * \ingroup bgpencil
  */
 
+#include <algorithm>
+
 #include "BLI_math_color.h"
 #include "BLI_math_matrix.h"
 #include "BLI_math_vector.h"
@@ -245,7 +247,7 @@ void GpencilExporterPDF::export_stroke_to_polyline(bGPDlayer *gpl,
     HPDF_Page_SetLineJoin(page_, HPDF_ROUND_JOIN);
     const float defined_width = (gps->thickness * avg_pressure) + gpl->line_change;
     const float estimated_width = (radius * 2.0f) + gpl->line_change;
-    const float final_width = (avg_pressure == 1.0f) ? MAX2(defined_width, estimated_width) :
+    const float final_width = (avg_pressure == 1.0f) ? std::max(defined_width, estimated_width) :
                                                        estimated_width;
     HPDF_Page_SetLineWidth(page_, std::max(final_width, 1.0f));
   }
diff --git a/source/blender/io/gpencil/intern/gpencil_io_export_svg.cc b/source/blender/io/gpencil/intern/gpencil_io_export_svg.cc
index 4921b003c328501736b46b49f3b38ddc140dbb81..6ecb1c40167ef0510bb99a710f2c8ce27e31f929 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_export_svg.cc
+++ b/source/blender/io/gpencil/intern/gpencil_io_export_svg.cc
@@ -6,6 +6,8 @@
  * \ingroup bgpencil
  */
 
+#include <algorithm>
+
 #include "BLI_math_color.h"
 #include "BLI_math_matrix.h"
 #include "BLI_math_vector.h"
@@ -313,7 +315,7 @@ void GpencilExporterSVG::export_stroke_to_polyline(bGPDlayer *gpl,
   if (is_stroke && !do_fill) {
     const float defined_width = (gps->thickness * avg_pressure) + gpl->line_change;
     const float estimated_width = (radius * 2.0f) + gpl->line_change;
-    const float final_width = (avg_pressure == 1.0f) ? MAX2(defined_width, estimated_width) :
+    const float final_width = (avg_pressure == 1.0f) ? std::max(defined_width, estimated_width) :
                                                        estimated_width;
     node_gps.append_attribute("stroke-width").set_value(std::max(final_width, 1.0f));
   }
diff --git a/source/blender/makesdna/intern/dna_genfile.cc b/source/blender/makesdna/intern/dna_genfile.cc
index 20e224968cc696e4236f77c63c970e53d7dfa675..6247701516c68a0ea4d670b3e49f5e48689f81b6 100644
--- a/source/blender/makesdna/intern/dna_genfile.cc
+++ b/source/blender/makesdna/intern/dna_genfile.cc
@@ -12,6 +12,7 @@
  * SDNA and the SDNA of the current (running) version of Blender.
  */
 
+#include <algorithm>
 #include <climits>
 #include <cstdio>
 #include <cstdlib>
@@ -1328,7 +1329,7 @@ static void init_reconstruct_step_for_member(const SDNA *oldsdna,
 
   const int new_array_length = newsdna->names_array_len[new_member->name];
   const int old_array_length = oldsdna->names_array_len[old_member->name];
-  const int shared_array_length = MIN2(new_array_length, old_array_length);
+  const int shared_array_length = std::min(new_array_length, old_array_length);
 
   const char *new_type_name = newsdna->types[new_member->type];
   const char *old_type_name = oldsdna->types[old_member->type];
diff --git a/source/blender/makesdna/intern/makesdna.cc b/source/blender/makesdna/intern/makesdna.cc
index 38f9bdcfdcca0f4814daa099a0af43c576236785..1f103abf706c860161a7dbcc011b972d26c1a19d 100644
--- a/source/blender/makesdna/intern/makesdna.cc
+++ b/source/blender/makesdna/intern/makesdna.cc
@@ -26,6 +26,7 @@
 
 #define DNA_DEPRECATED_ALLOW
 
+#include <algorithm>
 #include <cctype>
 #include <cstdio>
 #include <cstdlib>
@@ -1042,8 +1043,8 @@ static int calculate_struct_sizes(int firststruct, FILE *file_verify, const char
             size_native += sizeof(void *) * mul;
             size_32 += 4 * mul;
             size_64 += 8 * mul;
-            max_align_32 = MAX2(max_align_32, 4);
-            max_align_64 = MAX2(max_align_64, 8);
+            max_align_32 = std::max(max_align_32, 4);
+            max_align_64 = std::max(max_align_64, 8);
           }
           else if (cp[0] == '[') {
             /* parsing can cause names "var" and "[3]"
@@ -1097,8 +1098,8 @@ static int calculate_struct_sizes(int firststruct, FILE *file_verify, const char
             size_native += mul * types_size_native[type];
             size_32 += mul * types_size_32[type];
             size_64 += mul * types_size_64[type];
-            max_align_32 = MAX2(max_align_32, types_align_32[type]);
-            max_align_64 = MAX2(max_align_64, types_align_64[type]);
+            max_align_32 = std::max<int>(max_align_32, types_align_32[type]);
+            max_align_64 = std::max<int>(max_align_64, types_align_64[type]);
           }
           else {
             size_native = 0;
diff --git a/source/blender/makesrna/intern/makesrna.cc b/source/blender/makesrna/intern/makesrna.cc
index 722c71e053c11106725c6d093182716bbf743fe9..1d0193670c21f61e8006630f31f174f29840b504 100644
--- a/source/blender/makesrna/intern/makesrna.cc
+++ b/source/blender/makesrna/intern/makesrna.cc
@@ -6,6 +6,7 @@
  * \ingroup RNA
  */
 
+#include <algorithm>
 #include <cerrno>
 #include <cfloat>
 #include <cinttypes>
@@ -85,7 +86,7 @@ static const char *path_basename(const char *path)
     lfslash++;
   }
 
-  return MAX3(path, lfslash, lbslash);
+  return std::max({path, lfslash, lbslash});
 }
 
 /* forward declarations */
diff --git a/source/blender/makesrna/intern/rna_action.cc b/source/blender/makesrna/intern/rna_action.cc
index 93803e36d001d29ba92fa38c53ec68952fc53599..d723edd0c54fdfcafd0d5f79ecf17ee4d2df5a2c 100644
--- a/source/blender/makesrna/intern/rna_action.cc
+++ b/source/blender/makesrna/intern/rna_action.cc
@@ -30,6 +30,8 @@
 
 #ifdef RNA_RUNTIME
 
+#  include <algorithm>
+
 #  include "BLI_math_base.h"
 
 #  include "BKE_fcurve.h"
@@ -224,7 +226,7 @@ static void rna_Action_active_pose_marker_set(PointerRNA *ptr,
 static int rna_Action_active_pose_marker_index_get(PointerRNA *ptr)
 {
   bAction *act = (bAction *)ptr->data;
-  return MAX2(act->active_marker - 1, 0);
+  return std::max(act->active_marker - 1, 0);
 }
 
 static void rna_Action_active_pose_marker_index_set(PointerRNA *ptr, int value)
diff --git a/source/blender/makesrna/intern/rna_animation.cc b/source/blender/makesrna/intern/rna_animation.cc
index e57082cd68598672badd4645b97882c88b3a3ba3..fd7f6e3b3281feb3cd9a8ddaeb4b0badfa2ad213 100644
--- a/source/blender/makesrna/intern/rna_animation.cc
+++ b/source/blender/makesrna/intern/rna_animation.cc
@@ -87,6 +87,8 @@ const EnumPropertyItem rna_enum_keying_flag_api_items[] = {
 
 #ifdef RNA_RUNTIME
 
+#  include <algorithm>
+
 #  include "BLI_math_base.h"
 
 #  include "BKE_anim_data.h"
@@ -503,7 +505,7 @@ static void rna_KeyingSet_active_ksPath_set(PointerRNA *ptr,
 static int rna_KeyingSet_active_ksPath_index_get(PointerRNA *ptr)
 {
   KeyingSet *ks = (KeyingSet *)ptr->data;
-  return MAX2(ks->active_path - 1, 0);
+  return std::max(ks->active_path - 1, 0);
 }
 
 static void rna_KeyingSet_active_ksPath_index_set(PointerRNA *ptr, int value)
diff --git a/source/blender/makesrna/intern/rna_armature.cc b/source/blender/makesrna/intern/rna_armature.cc
index 480f4535e70f21d7ef8ee6da758f9de792291463..0599559fd4a43501667ab2fe0dce1fb5b89ed263 100644
--- a/source/blender/makesrna/intern/rna_armature.cc
+++ b/source/blender/makesrna/intern/rna_armature.cc
@@ -1459,7 +1459,7 @@ static void rna_def_bone_common(StructRNA *srna, int editbone)
     RNA_def_property_update(prop, 0, "rna_Armature_update_data");
   }
   RNA_def_property_float_sdna(prop, nullptr, "rad_head");
-  /* XXX: range is 0 to limit, where `limit = 10000.0f * MAX2(1.0, view3d->grid)`. */
+  /* XXX: range is 0 to limit, where `limit = 10000.0f * std::max(1.0, view3d->grid)`. */
   // RNA_def_property_range(prop, 0, 1000);
   RNA_def_property_ui_range(prop, 0.01, 100, 0.1, 3);
   RNA_def_property_ui_text(
@@ -1473,7 +1473,7 @@ static void rna_def_bone_common(StructRNA *srna, int editbone)
     RNA_def_property_update(prop, 0, "rna_Armature_update_data");
   }
   RNA_def_property_float_sdna(prop, nullptr, "rad_tail");
-  /* XXX range is 0 to limit, where limit = `10000.0f * MAX2(1.0, view3d->grid)`. */
+  /* XXX range is 0 to limit, where limit = `10000.0f * std::max(1.0, view3d->grid)`. */
   // RNA_def_property_range(prop, 0, 1000);
   RNA_def_property_ui_range(prop, 0.01, 100, 0.1, 3);
   RNA_def_property_ui_text(
diff --git a/source/blender/makesrna/intern/rna_asset.cc b/source/blender/makesrna/intern/rna_asset.cc
index 34a7b7cc37b88303d4eb15da3ded053c05e99382..1fd05dd3ba4f8141a05c41e29a477b674d72dcd5 100644
--- a/source/blender/makesrna/intern/rna_asset.cc
+++ b/source/blender/makesrna/intern/rna_asset.cc
@@ -41,6 +41,8 @@ const EnumPropertyItem rna_enum_asset_library_type_items[] = {
 
 #ifdef RNA_RUNTIME
 
+#  include <algorithm>
+
 #  include "AS_asset_library.h"
 #  include "AS_asset_representation.hh"
 
@@ -307,7 +309,7 @@ static void rna_AssetMetaData_active_tag_range(
 {
   const AssetMetaData *asset_data = static_cast<const AssetMetaData *>(ptr->data);
   *min = *softmin = 0;
-  *max = *softmax = MAX2(asset_data->tot_tags - 1, 0);
+  *max = *softmax = std::max(int(asset_data->tot_tags - 1), 0);
 }
 
 static void rna_AssetMetaData_catalog_id_get(PointerRNA *ptr, char *value)
diff --git a/source/blender/makesrna/intern/rna_gpencil_legacy_modifier.cc b/source/blender/makesrna/intern/rna_gpencil_legacy_modifier.cc
index 31fbf3f7480d8bf74824f707874f5690ccacae97..464894c9aa92b6ef2cd8cee58fc1a5bea3a03165 100644
--- a/source/blender/makesrna/intern/rna_gpencil_legacy_modifier.cc
+++ b/source/blender/makesrna/intern/rna_gpencil_legacy_modifier.cc
@@ -271,6 +271,8 @@ static const EnumPropertyItem modifier_noise_random_mode_items[] = {
 
 #ifdef RNA_RUNTIME
 
+#  include <algorithm>
+
 #  include "DNA_curve_types.h"
 #  include "DNA_fluid_types.h"
 #  include "DNA_material_types.h"
@@ -488,7 +490,7 @@ static void rna_TimeModifier_start_frame_set(PointerRNA *ptr, int value)
   tmd->sfra = value;
 
   if (tmd->sfra >= tmd->efra) {
-    tmd->efra = MIN2(tmd->sfra, MAXFRAME);
+    tmd->efra = std::min(tmd->sfra, MAXFRAME);
   }
 }
 
@@ -499,7 +501,7 @@ static void rna_TimeModifier_end_frame_set(PointerRNA *ptr, int value)
   tmd->efra = value;
 
   if (tmd->sfra >= tmd->efra) {
-    tmd->sfra = MAX2(tmd->efra, MINFRAME);
+    tmd->sfra = std::max(tmd->efra, MINFRAME);
   }
 }
 
@@ -795,7 +797,7 @@ static void rna_Lineart_start_level_set(PointerRNA *ptr, int value)
 
   CLAMP(value, 0, 128);
   lmd->level_start = value;
-  lmd->level_end = MAX2(value, lmd->level_end);
+  lmd->level_end = std::max<short>(value, lmd->level_end);
 }
 
 static void rna_Lineart_end_level_set(PointerRNA *ptr, int value)
@@ -804,7 +806,7 @@ static void rna_Lineart_end_level_set(PointerRNA *ptr, int value)
 
   CLAMP(value, 0, 128);
   lmd->level_end = value;
-  lmd->level_start = MIN2(value, lmd->level_start);
+  lmd->level_start = std::min<short>(value, lmd->level_start);
 }
 
 static void rna_GpencilDash_segments_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
diff --git a/source/blender/makesrna/intern/rna_key.cc b/source/blender/makesrna/intern/rna_key.cc
index 27773b862ff72c86922efda457c59cc38484cf5a..08f282ff491341615bfa8fab7bdc93d5773086ed 100644
--- a/source/blender/makesrna/intern/rna_key.cc
+++ b/source/blender/makesrna/intern/rna_key.cc
@@ -38,6 +38,7 @@ const EnumPropertyItem rna_enum_keyblock_type_items[] = {
 
 #ifdef RNA_RUNTIME
 
+#  include <algorithm>
 #  include <stddef.h>
 
 #  include "DNA_object_types.h"
@@ -491,11 +492,11 @@ static void rna_ShapeKey_NurbInfo_step(NurbInfo *r_info,
   rna_ShapeKey_NurbInfo_init(r_info, nu);
 
   if (input_elem) {
-    r_info->nurb_index = MIN2(r_info->nurb_size, *p_raw_index / r_info->nurb_elem_step);
+    r_info->nurb_index = std::min(r_info->nurb_size, *p_raw_index / r_info->nurb_elem_step);
     *p_raw_index -= r_info->nurb_size * r_info->nurb_elem_step;
   }
   else {
-    r_info->nurb_index = MIN2(r_info->nurb_size, *p_raw_index);
+    r_info->nurb_index = std::min(r_info->nurb_size, *p_raw_index);
     *p_raw_index -= r_info->nurb_size;
   }
 
diff --git a/source/blender/makesrna/intern/rna_mask.cc b/source/blender/makesrna/intern/rna_mask.cc
index be870ac103d035b0799231c4a14981c36ae86235..5244f2c81941be68fcd5da4732b13bc93bdaac90 100644
--- a/source/blender/makesrna/intern/rna_mask.cc
+++ b/source/blender/makesrna/intern/rna_mask.cc
@@ -35,6 +35,8 @@
 
 #ifdef RNA_RUNTIME
 
+#  include <algorithm>
+
 #  include "DNA_movieclip_types.h"
 
 #  include "BKE_mask.h"
@@ -461,7 +463,7 @@ static void rna_Mask_start_frame_set(PointerRNA *ptr, int value)
   data->sfra = value;
 
   if (data->sfra >= data->efra) {
-    data->efra = MIN2(data->sfra, MAXFRAME);
+    data->efra = std::min(data->sfra, MAXFRAME);
   }
 }
 
@@ -472,7 +474,7 @@ static void rna_Mask_end_frame_set(PointerRNA *ptr, int value)
   data->efra = value;
 
   if (data->sfra >= data->efra) {
-    data->sfra = MAX2(data->efra, MINFRAME);
+    data->sfra = std::max(data->efra, MINFRAME);
   }
 }
 
diff --git a/source/blender/makesrna/intern/rna_mesh_utils.hh b/source/blender/makesrna/intern/rna_mesh_utils.hh
index e2b867d0035775268e2062c5daf211b547a2f90d..f56a99eb3c08da53e76433330ea4219e2cd8aa0b 100644
--- a/source/blender/makesrna/intern/rna_mesh_utils.hh
+++ b/source/blender/makesrna/intern/rna_mesh_utils.hh
@@ -53,7 +53,7 @@
     *max = data ? CustomData_number_of_layers(data, layer_type) - \
                       CustomData_number_of_anonymous_layers(data, layer_type) - 1 : \
                   0; \
-    *max = MAX2(0, *max); \
+    *max = std::max(0, *max); \
   }
 
 /* Define the accessors for special CustomDataLayers in the collection
diff --git a/source/blender/makesrna/intern/rna_object.cc b/source/blender/makesrna/intern/rna_object.cc
index eb80ed94e87340a3d03571f96a6bde2eddb64403..6c212f01ebff1a12f80ae46fd17655c24afa8812 100644
--- a/source/blender/makesrna/intern/rna_object.cc
+++ b/source/blender/makesrna/intern/rna_object.cc
@@ -314,6 +314,8 @@ const EnumPropertyItem rna_enum_object_axis_items[] = {
 
 #ifdef RNA_RUNTIME
 
+#  include <algorithm>
+
 #  include "DNA_ID.h"
 #  include "DNA_constraint_types.h"
 #  include "DNA_gpencil_legacy_types.h"
@@ -1096,7 +1098,7 @@ void rna_object_vcollayer_name_set(PointerRNA *ptr,
 static int rna_Object_active_material_index_get(PointerRNA *ptr)
 {
   Object *ob = reinterpret_cast<Object *>(ptr->owner_id);
-  return MAX2(ob->actcol - 1, 0);
+  return std::max<int>(ob->actcol - 1, 0);
 }
 
 static void rna_Object_active_material_index_set(PointerRNA *ptr, int value)
@@ -1544,7 +1546,7 @@ static int rna_Object_active_shape_key_index_get(PointerRNA *ptr)
 {
   Object *ob = reinterpret_cast<Object *>(ptr->owner_id);
 
-  return MAX2(ob->shapenr - 1, 0);
+  return std::max<int>(ob->shapenr - 1, 0);
 }
 
 static void rna_Object_active_shape_key_index_set(PointerRNA *ptr, int value)
diff --git a/source/blender/makesrna/intern/rna_scene.cc b/source/blender/makesrna/intern/rna_scene.cc
index 008ce861099d866f2dea508d685d17a0517b4b07..647609d13a4af27ac401132eb505817df6ed5e18 100644
--- a/source/blender/makesrna/intern/rna_scene.cc
+++ b/source/blender/makesrna/intern/rna_scene.cc
@@ -707,6 +707,8 @@ const EnumPropertyItem rna_enum_grease_pencil_selectmode_items[] = {
 
 #ifdef RNA_RUNTIME
 
+#  include <algorithm>
+
 #  include "BLI_string_utils.hh"
 
 #  include "DNA_anim_types.h"
@@ -1053,7 +1055,7 @@ static void rna_Scene_start_frame_set(PointerRNA *ptr, int value)
   data->r.sfra = value;
 
   if (value > data->r.efra) {
-    data->r.efra = MIN2(value, MAXFRAME);
+    data->r.efra = std::min(value, MAXFRAME);
   }
 }
 
@@ -1064,7 +1066,7 @@ static void rna_Scene_end_frame_set(PointerRNA *ptr, int value)
   data->r.efra = value;
 
   if (data->r.sfra > value) {
-    data->r.sfra = MAX2(value, MINFRAME);
+    data->r.sfra = std::max(value, MINFRAME);
   }
 }
 
@@ -1100,7 +1102,7 @@ static void rna_Scene_preview_range_start_frame_set(PointerRNA *ptr, int value)
   data->r.psfra = value;
 
   if (value > data->r.pefra) {
-    data->r.pefra = MIN2(value, MAXFRAME);
+    data->r.pefra = std::min(value, MAXFRAME);
   }
 }
 
@@ -1118,7 +1120,7 @@ static void rna_Scene_preview_range_end_frame_set(PointerRNA *ptr, int value)
   data->r.pefra = value;
 
   if (data->r.psfra > value) {
-    data->r.psfra = MAX2(value, MINAFRAME);
+    data->r.psfra = std::max(value, MINAFRAME);
   }
 }
 
diff --git a/source/blender/makesrna/intern/rna_sequencer.cc b/source/blender/makesrna/intern/rna_sequencer.cc
index 773cac5650a11ba433d325048105ad9d2b9b3775..decdf2abd20f21c9d015000685f148f191a0527d 100644
--- a/source/blender/makesrna/intern/rna_sequencer.cc
+++ b/source/blender/makesrna/intern/rna_sequencer.cc
@@ -111,6 +111,8 @@ const EnumPropertyItem rna_enum_strip_color_items[] = {
 
 #ifdef RNA_RUNTIME
 
+#  include <algorithm>
+
 #  include "BKE_global.h"
 #  include "BKE_idprop.h"
 #  include "BKE_movieclip.h"
@@ -501,7 +503,7 @@ static void rna_Sequence_anim_startofs_final_set(PointerRNA *ptr, int value)
   Sequence *seq = (Sequence *)ptr->data;
   Scene *scene = (Scene *)ptr->owner_id;
 
-  seq->anim_startofs = MIN2(value, seq->len + seq->anim_startofs);
+  seq->anim_startofs = std::min(value, seq->len + seq->anim_startofs);
 
   SEQ_add_reload_new_file(G.main, scene, seq, false);
   do_sequence_frame_change_update(scene, seq);
@@ -512,7 +514,7 @@ static void rna_Sequence_anim_endofs_final_set(PointerRNA *ptr, int value)
   Sequence *seq = (Sequence *)ptr->data;
   Scene *scene = (Scene *)ptr->owner_id;
 
-  seq->anim_endofs = MIN2(value, seq->len + seq->anim_endofs);
+  seq->anim_endofs = std::min(value, seq->len + seq->anim_endofs);
 
   SEQ_add_reload_new_file(G.main, scene, seq, false);
   do_sequence_frame_change_update(scene, seq);
diff --git a/source/blender/modifiers/intern/MOD_surfacedeform.cc b/source/blender/modifiers/intern/MOD_surfacedeform.cc
index d932e3277f5837edbf8f7529442e27472121e0f7..cd8568d92eace2932279b5c6c16e63b69582cb72 100644
--- a/source/blender/modifiers/intern/MOD_surfacedeform.cc
+++ b/source/blender/modifiers/intern/MOD_surfacedeform.cc
@@ -1367,7 +1367,7 @@ static void deformVert(void *__restrict userdata,
 
   int max_verts = 0;
   for (int j = 0; j < sdbind_num; j++) {
-    max_verts = MAX2(max_verts, sdbind[j].verts_num);
+    max_verts = std::max(max_verts, int(sdbind[j].verts_num));
   }
 
   /* Allocate a `coords_buffer` that fits all the temp-data. */
diff --git a/source/blender/python/generic/idprop_py_api.cc b/source/blender/python/generic/idprop_py_api.cc
index db8c2c673fecf134fbd2f9e1ef01bf71f23b8701..99c0f5a3f90c9db0971568443c6f2820d588cd61 100644
--- a/source/blender/python/generic/idprop_py_api.cc
+++ b/source/blender/python/generic/idprop_py_api.cc
@@ -6,6 +6,8 @@
  * \ingroup pygen
  */
 
+#include <algorithm>
+
 #include <Python.h>
 
 #include "MEM_guardedalloc.h"
@@ -1900,7 +1902,7 @@ static PyObject *BPy_IDArray_slice(BPy_IDArray *self, int begin, int end)
     end = prop->len + end + 1;
   }
   CLAMP(end, 0, prop->len);
-  begin = MIN2(begin, end);
+  begin = std::min(begin, end);
 
   tuple = PyTuple_New(end - begin);
 
@@ -1949,7 +1951,7 @@ static int BPy_IDArray_ass_slice(BPy_IDArray *self, int begin, int end, PyObject
 
   CLAMP(begin, 0, prop->len);
   CLAMP(end, 0, prop->len);
-  begin = MIN2(begin, end);
+  begin = std::min(begin, end);
 
   size = (end - begin);
   alloc_len = size * elem_size;
diff --git a/source/blender/python/generic/idprop_py_ui_api.cc b/source/blender/python/generic/idprop_py_ui_api.cc
index 3494d7f79719e9f8b647d67a4a310b71cc27e233..75fe1ddbfb8fc23d54081e3a5650008d621c0701 100644
--- a/source/blender/python/generic/idprop_py_ui_api.cc
+++ b/source/blender/python/generic/idprop_py_ui_api.cc
@@ -501,12 +501,12 @@ static bool idprop_ui_data_update_float(IDProperty *idprop, PyObject *args, PyOb
   }
   if (args_contain_key(kwargs, "soft_min")) {
     ui_data.soft_min = soft_min;
-    ui_data.soft_min = MAX2(ui_data.soft_min, ui_data.min);
+    ui_data.soft_min = std::max(ui_data.soft_min, ui_data.min);
     ui_data.soft_max = std::max(ui_data.soft_min, ui_data.soft_max);
   }
   if (args_contain_key(kwargs, "soft_max")) {
     ui_data.soft_max = soft_max;
-    ui_data.soft_max = MIN2(ui_data.soft_max, ui_data.max);
+    ui_data.soft_max = std::min(ui_data.soft_max, ui_data.max);
     ui_data.soft_min = std::min(ui_data.soft_min, ui_data.soft_max);
   }
   if (args_contain_key(kwargs, "step")) {
diff --git a/source/blender/python/intern/bpy_props.cc b/source/blender/python/intern/bpy_props.cc
index 8b1d6557023ead10945e4d5be1c267d27f1cb722..d6e549aaa154cd5b971bd51cba8d3ce9b072ac36 100644
--- a/source/blender/python/intern/bpy_props.cc
+++ b/source/blender/python/intern/bpy_props.cc
@@ -13,6 +13,8 @@
 /* Future-proof, See https://docs.python.org/3/c-api/arg.html#strings-and-buffers */
 #define PY_SSIZE_T_CLEAN
 
+#include <algorithm>
+
 #include <Python.h>
 
 #include "RNA_types.hh"
@@ -3268,7 +3270,7 @@ static PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
     RNA_def_property_translation_context(prop, translation_context);
   }
   RNA_def_property_range(prop, min, max);
-  RNA_def_property_ui_range(prop, std::max(soft_min, min), MIN2(soft_max, max), step, 3);
+  RNA_def_property_ui_range(prop, std::max(soft_min, min), std::min(soft_max, max), step, 3);
 
   if (tags_enum.base.is_set) {
     RNA_def_property_tags(prop, tags_enum.base.value);
@@ -3467,7 +3469,7 @@ static PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject
   if (translation_context) {
     RNA_def_property_translation_context(prop, translation_context);
   }
-  RNA_def_property_ui_range(prop, std::max(soft_min, min), MIN2(soft_max, max), step, 3);
+  RNA_def_property_ui_range(prop, std::max(soft_min, min), std::min(soft_max, max), step, 3);
 
   if (tags_enum.base.is_set) {
     RNA_def_property_tags(prop, tags_enum.base.value);
@@ -3643,7 +3645,8 @@ static PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
   if (translation_context) {
     RNA_def_property_translation_context(prop, translation_context);
   }
-  RNA_def_property_ui_range(prop, MAX2(soft_min, min), MIN2(soft_max, max), step, precision);
+  RNA_def_property_ui_range(
+      prop, std::max(soft_min, min), std::min(soft_max, max), step, precision);
 
   if (tags_enum.base.is_set) {
     RNA_def_property_tags(prop, tags_enum.base.value);
@@ -3859,7 +3862,8 @@ static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObjec
   if (translation_context) {
     RNA_def_property_translation_context(prop, translation_context);
   }
-  RNA_def_property_ui_range(prop, MAX2(soft_min, min), MIN2(soft_max, max), step, precision);
+  RNA_def_property_ui_range(
+      prop, std::max(soft_min, min), std::min(soft_max, max), step, precision);
 
   if (tags_enum.base.is_set) {
     RNA_def_property_tags(prop, tags_enum.base.value);
diff --git a/source/blender/python/mathutils/mathutils_Color.cc b/source/blender/python/mathutils/mathutils_Color.cc
index 5f6cb997047314abfa2617d1a93cf317a4470b7d..03f60079f3eee67981995c6c5434b122bd1e2609 100644
--- a/source/blender/python/mathutils/mathutils_Color.cc
+++ b/source/blender/python/mathutils/mathutils_Color.cc
@@ -6,6 +6,8 @@
  * \ingroup pymathutils
  */
 
+#include <algorithm>
+
 #include <Python.h>
 
 #include "mathutils.h"
@@ -431,7 +433,7 @@ static PyObject *Color_slice(ColorObject *self, int begin, int end)
     end = (COLOR_SIZE + 1) + end;
   }
   CLAMP(end, 0, COLOR_SIZE);
-  begin = MIN2(begin, end);
+  begin = std::min(begin, end);
 
   tuple = PyTuple_New(end - begin);
   for (count = begin; count < end; count++) {
@@ -456,7 +458,7 @@ static int Color_ass_slice(ColorObject *self, int begin, int end, PyObject *seq)
     end = (COLOR_SIZE + 1) + end;
   }
   CLAMP(end, 0, COLOR_SIZE);
-  begin = MIN2(begin, end);
+  begin = std::min(begin, end);
 
   if ((size = mathutils_array_parse(col, 0, COLOR_SIZE, seq, "mathutils.Color[begin:end] = []")) ==
       -1)
diff --git a/source/blender/python/mathutils/mathutils_Euler.cc b/source/blender/python/mathutils/mathutils_Euler.cc
index 6baea906683f51d7016f5dcac134d8bf70fd9975..c148ce38e2b16a0283e76ca169e7622aaf878bf2 100644
--- a/source/blender/python/mathutils/mathutils_Euler.cc
+++ b/source/blender/python/mathutils/mathutils_Euler.cc
@@ -6,6 +6,8 @@
  * \ingroup pymathutils
  */
 
+#include <algorithm>
+
 #include <Python.h>
 
 #include "mathutils.h"
@@ -517,7 +519,7 @@ static PyObject *Euler_slice(EulerObject *self, int begin, int end)
     end = (EULER_SIZE + 1) + end;
   }
   CLAMP(end, 0, EULER_SIZE);
-  begin = MIN2(begin, end);
+  begin = std::min(begin, end);
 
   tuple = PyTuple_New(end - begin);
   for (count = begin; count < end; count++) {
@@ -542,7 +544,7 @@ static int Euler_ass_slice(EulerObject *self, int begin, int end, PyObject *seq)
     end = (EULER_SIZE + 1) + end;
   }
   CLAMP(end, 0, EULER_SIZE);
-  begin = MIN2(begin, end);
+  begin = std::min(begin, end);
 
   if ((size = mathutils_array_parse(eul, 0, EULER_SIZE, seq, "mathutils.Euler[begin:end] = []")) ==
       -1)
diff --git a/source/blender/python/mathutils/mathutils_Matrix.cc b/source/blender/python/mathutils/mathutils_Matrix.cc
index 4d7a9c93250cfab8c1b2aad1e9f12707f4bcbb62..c4f64ec71bc8153c058005f708d782323931f398 100644
--- a/source/blender/python/mathutils/mathutils_Matrix.cc
+++ b/source/blender/python/mathutils/mathutils_Matrix.cc
@@ -6,6 +6,8 @@
  * \ingroup pymathutils
  */
 
+#include <algorithm>
+
 #include <Python.h>
 
 #include "mathutils.h"
@@ -2508,7 +2510,7 @@ static PyObject *Matrix_slice(MatrixObject *self, int begin, int end)
 
   CLAMP(begin, 0, self->row_num);
   CLAMP(end, 0, self->row_num);
-  begin = MIN2(begin, end);
+  begin = std::min(begin, end);
 
   tuple = PyTuple_New(end - begin);
   for (count = begin; count < end; count++) {
@@ -2532,7 +2534,7 @@ static int Matrix_ass_slice(MatrixObject *self, int begin, int end, PyObject *va
 
   CLAMP(begin, 0, self->row_num);
   CLAMP(end, 0, self->row_num);
-  begin = MIN2(begin, end);
+  begin = std::min(begin, end);
 
   /* non list/tuple cases */
   if (!(value_fast = PySequence_Fast(value, "matrix[begin:end] = value"))) {
diff --git a/source/blender/python/mathutils/mathutils_Quaternion.cc b/source/blender/python/mathutils/mathutils_Quaternion.cc
index 9ac93931eecf078278a7a9e71a6d5dfda17d9339..0eb6f7d9de24644bd0d5d77df3c38b5449a0607f 100644
--- a/source/blender/python/mathutils/mathutils_Quaternion.cc
+++ b/source/blender/python/mathutils/mathutils_Quaternion.cc
@@ -6,6 +6,8 @@
  * \ingroup pymathutils
  */
 
+#include <algorithm>
+
 #include <Python.h>
 
 #include "mathutils.h"
@@ -969,7 +971,7 @@ static PyObject *Quaternion_slice(QuaternionObject *self, int begin, int end)
     end = (QUAT_SIZE + 1) + end;
   }
   CLAMP(end, 0, QUAT_SIZE);
-  begin = MIN2(begin, end);
+  begin = std::min(begin, end);
 
   tuple = PyTuple_New(end - begin);
   for (count = begin; count < end; count++) {
@@ -994,7 +996,7 @@ static int Quaternion_ass_slice(QuaternionObject *self, int begin, int end, PyOb
     end = (QUAT_SIZE + 1) + end;
   }
   CLAMP(end, 0, QUAT_SIZE);
-  begin = MIN2(begin, end);
+  begin = std::min(begin, end);
 
   if ((size = mathutils_array_parse(
            quat, 0, QUAT_SIZE, seq, "mathutils.Quaternion[begin:end] = []")) == -1)
diff --git a/source/blender/python/mathutils/mathutils_Vector.cc b/source/blender/python/mathutils/mathutils_Vector.cc
index f38943c336117ba3435e6b7df60df17bfa83e831..34aa68ce8dfabe80bee6d1191e47e74137cbdbc1 100644
--- a/source/blender/python/mathutils/mathutils_Vector.cc
+++ b/source/blender/python/mathutils/mathutils_Vector.cc
@@ -6,6 +6,8 @@
  * \ingroup pymathutils
  */
 
+#include <algorithm>
+
 #include <Python.h>
 
 #include "mathutils.h"
@@ -1782,7 +1784,7 @@ static PyObject *Vector_slice(VectorObject *self, int begin, int end)
     end = self->vec_num + end + 1;
   }
   CLAMP(end, 0, self->vec_num);
-  begin = MIN2(begin, end);
+  begin = std::min(begin, end);
 
   tuple = PyTuple_New(end - begin);
   for (count = begin; count < end; count++) {
@@ -1804,7 +1806,7 @@ static int Vector_ass_slice(VectorObject *self, int begin, int end, PyObject *se
 
   CLAMP(begin, 0, self->vec_num);
   CLAMP(end, 0, self->vec_num);
-  begin = MIN2(begin, end);
+  begin = std::min(begin, end);
 
   vec_num = (end - begin);
   if (mathutils_array_parse_alloc(&vec, vec_num, seq, "vector[begin:end] = [...]") == -1) {
diff --git a/source/blender/render/intern/texture_image.cc b/source/blender/render/intern/texture_image.cc
index a9d48b33831e3ec2bed85876f366e7935396ec65..ec564dd0e72125b8f2a0a38b3887c8bdb7642155 100644
--- a/source/blender/render/intern/texture_image.cc
+++ b/source/blender/render/intern/texture_image.cc
@@ -6,6 +6,7 @@
  * \ingroup render
  */
 
+#include <algorithm>
 #include <cfloat>
 #include <cmath>
 #include <cstdio>
@@ -1035,7 +1036,7 @@ static int imagewraposa_aniso(Tex *tex,
   if (tex->imaflag & TEX_FILTER_MIN) {
     /* Make sure the filtersize is minimal in pixels
      * (normal, ref map can have miniature pixel dx/dy). */
-    const float addval = (0.5f * tex->filtersize) / float(MIN2(ibuf->x, ibuf->y));
+    const float addval = (0.5f * tex->filtersize) / float(std::min(ibuf->x, ibuf->y));
     if (addval > minx) {
       minx = addval;
     }
@@ -1438,7 +1439,7 @@ int imagewraposa(Tex *tex,
   if (tex->imaflag & TEX_FILTER_MIN) {
     /* Make sure the filtersize is minimal in pixels
      * (normal, ref map can have miniature pixel dx/dy). */
-    float addval = (0.5f * tex->filtersize) / float(MIN2(ibuf->x, ibuf->y));
+    float addval = (0.5f * tex->filtersize) / float(std::min(ibuf->x, ibuf->y));
 
     if (addval > minx) {
       minx = addval;
@@ -1641,7 +1642,7 @@ int imagewraposa(Tex *tex,
       maxd = 0.5f;
     }
 
-    pixsize = 1.0f / float(MIN2(ibuf->x, ibuf->y));
+    pixsize = 1.0f / float(std::min(ibuf->x, ibuf->y));
 
     curmap = 0;
     previbuf = curibuf = ibuf;
@@ -1651,7 +1652,7 @@ int imagewraposa(Tex *tex,
       }
       previbuf = curibuf;
       curibuf = ibuf->mipmap[curmap];
-      pixsize = 1.0f / float(MIN2(curibuf->x, curibuf->y));
+      pixsize = 1.0f / float(std::min(curibuf->x, curibuf->y));
       curmap++;
     }
 
diff --git a/source/blender/sequencer/intern/sound.cc b/source/blender/sequencer/intern/sound.cc
index c99086388eb14026dda02f1b4ebe223817f819a7..b551551aa7629a8d9a20c791d0d3a0aceed75506 100644
--- a/source/blender/sequencer/intern/sound.cc
+++ b/source/blender/sequencer/intern/sound.cc
@@ -8,6 +8,7 @@
  * \ingroup bke
  */
 
+#include <algorithm>
 #include <cmath>
 #include <cstring>
 
@@ -63,7 +64,7 @@ static bool sequencer_refresh_sound_length_recursive(Main *bmain, Scene *scene,
       int old = seq->len;
       float fac;
 
-      seq->len = MAX2(1, round((info.length - seq->sound->offset_time) * FPS));
+      seq->len = std::max(1, int(round((info.length - seq->sound->offset_time) * FPS)));
       fac = float(seq->len) / float(old);
       old = seq->startofs;
       seq->startofs *= fac;
diff --git a/source/blender/sequencer/intern/strip_add.cc b/source/blender/sequencer/intern/strip_add.cc
index 3f63f32b44ccbc26fca29dbcf6fc9b182e66d5df..eba8243313ac46b56c658cf1a35b110fd55cea7d 100644
--- a/source/blender/sequencer/intern/strip_add.cc
+++ b/source/blender/sequencer/intern/strip_add.cc
@@ -8,6 +8,7 @@
  * \ingroup bke
  */
 
+#include <algorithm>
 #include <cmath>
 #include <cstring>
 
@@ -323,7 +324,7 @@ Sequence *SEQ_add_sound_strip(Main *bmain, Scene *scene, ListBase *seqbase, SeqL
    * nearest frame as the audio track usually overshoots or undershoots the
    * end frame of the video by a little bit.
    * See #47135 for under shoot example. */
-  seq->len = MAX2(1, round((info.length - sound->offset_time) * FPS));
+  seq->len = std::max(1, int(round((info.length - sound->offset_time) * FPS)));
 
   Strip *strip = seq->strip;
   /* We only need 1 element to store the filename. */
diff --git a/source/blender/sequencer/intern/utils.cc b/source/blender/sequencer/intern/utils.cc
index 577b877022053816dbbeec7231967ecd1525ac88..c72c86fe515fdd3b4c1142be502f843aa8eeec2b 100644
--- a/source/blender/sequencer/intern/utils.cc
+++ b/source/blender/sequencer/intern/utils.cc
@@ -8,6 +8,7 @@
  * \ingroup bke
  */
 
+#include <algorithm>
 #include <cstdlib>
 #include <cstring>
 
@@ -498,14 +499,14 @@ void SEQ_set_scale_to_fit(const Sequence *seq,
 
   switch (fit_method) {
     case SEQ_SCALE_TO_FIT:
-      transform->scale_x = transform->scale_y = MIN2(float(preview_width) / float(image_width),
-                                                     float(preview_height) / float(image_height));
+      transform->scale_x = transform->scale_y = std::min(
+          float(preview_width) / float(image_width), float(preview_height) / float(image_height));
 
       break;
     case SEQ_SCALE_TO_FILL:
 
-      transform->scale_x = transform->scale_y = MAX2(float(preview_width) / float(image_width),
-                                                     float(preview_height) / float(image_height));
+      transform->scale_x = transform->scale_y = std::max(
+          float(preview_width) / float(image_width), float(preview_height) / float(image_height));
       break;
     case SEQ_STRETCH_TO_FILL:
       transform->scale_x = float(preview_width) / float(image_width);
diff --git a/source/blender/simulation/intern/implicit_blender.cc b/source/blender/simulation/intern/implicit_blender.cc
index fed6298ec9470e8f2d924c4a2a7883862cea0c10..613e12ab0b4bebb42820ec92daf3e6d12655ee08 100644
--- a/source/blender/simulation/intern/implicit_blender.cc
+++ b/source/blender/simulation/intern/implicit_blender.cc
@@ -1654,7 +1654,7 @@ BLI_INLINE void dfdx_damp(float to[3][3],
   // return (I - outerprod(dir, dir)) * (-damping * -(dot(dir, vel) / Max(length, rest)));
   mul_fvectorT_fvector(to, dir, dir);
   sub_fmatrix_fmatrix(to, I, to);
-  mul_fmatrix_S(to, (-damping * -(dot_v3v3(dir, vel) / MAX2(length, rest))));
+  mul_fmatrix_S(to, (-damping * -(dot_v3v3(dir, vel) / std::max(length, rest))));
 }
 #  endif
 
diff --git a/source/blender/simulation/intern/implicit_eigen.cc b/source/blender/simulation/intern/implicit_eigen.cc
index eb49a4eb16c00f26cbec063a4979eda1ade73c09..6bf489d53cd39261e2d7a4cd8624102186768db9 100644
--- a/source/blender/simulation/intern/implicit_eigen.cc
+++ b/source/blender/simulation/intern/implicit_eigen.cc
@@ -873,7 +873,7 @@ BLI_INLINE void dfdx_damp(float to[3][3],
   // return (I - outerprod(dir, dir)) * (-damping * -(dot(dir, vel) / Max(length, rest)));
   mul_fvectorT_fvector(to, dir, dir);
   sub_fmatrix_fmatrix(to, I, to);
-  mul_fmatrix_S(to, (-damping * -(dot_v3v3(dir, vel) / MAX2(length, rest))));
+  mul_fmatrix_S(to, (-damping * -(dot_v3v3(dir, vel) / std::max(length, rest))));
 }
 #  endif
 
diff --git a/source/blender/windowmanager/intern/wm_operators.cc b/source/blender/windowmanager/intern/wm_operators.cc
index 4d2e1d66dfc769ba8916cfe27b1d755a00779e28..6173b0d8137dcffc599feff0e2b8b57699b52a54 100644
--- a/source/blender/windowmanager/intern/wm_operators.cc
+++ b/source/blender/windowmanager/intern/wm_operators.cc
@@ -9,6 +9,7 @@
  * as well as some generic operators and shared operator properties.
  */
 
+#include <algorithm>
 #include <cctype>
 #include <cerrno>
 #include <cfloat>
@@ -1245,18 +1246,18 @@ static uiBlock *wm_block_confirm_create(bContext *C, ARegion *region, void *arg_
   UI_block_flag_enable(block, block_flags);
 
   const uiStyle *style = UI_style_get_dpi();
-  int text_width = MAX2(
+  int text_width = std::max(
       120 * UI_SCALE_FAC,
       BLF_width(style->widget.uifont_id, confirm.title, ARRAY_SIZE(confirm.title)));
   if (confirm.message[0]) {
-    text_width = MAX2(
+    text_width = std::max(
         text_width,
-        BLF_width(style->widget.uifont_id, confirm.message, ARRAY_SIZE(confirm.message)));
+        int(BLF_width(style->widget.uifont_id, confirm.message, ARRAY_SIZE(confirm.message))));
   }
   if (confirm.message2[0]) {
-    text_width = MAX2(
+    text_width = std::max(
         text_width,
-        BLF_width(style->widget.uifont_id, confirm.message2, ARRAY_SIZE(confirm.message2)));
+        int(BLF_width(style->widget.uifont_id, confirm.message2, ARRAY_SIZE(confirm.message2))));
   }
 
   const bool small = confirm.size == WM_WARNING_SIZE_SMALL;
diff --git a/source/blender/windowmanager/intern/wm_splash_screen.cc b/source/blender/windowmanager/intern/wm_splash_screen.cc
index c034fe3222e88e1f1f3d1312ca0ea2236af8c73a..6958544c74d91b765b174068086de1394f8f650a 100644
--- a/source/blender/windowmanager/intern/wm_splash_screen.cc
+++ b/source/blender/windowmanager/intern/wm_splash_screen.cc
@@ -14,6 +14,7 @@
  * - Links to web sites.
  */
 
+#include <algorithm>
 #include <cstring>
 
 #include "CLG_log.h"
@@ -181,7 +182,7 @@ static uiBlock *wm_block_create_splash(bContext *C, ARegion *region, void * /*ar
   UI_block_flag_enable(block, UI_BLOCK_LOOP | UI_BLOCK_KEEP_OPEN | UI_BLOCK_NO_WIN_CLIP);
   UI_block_theme_style_set(block, UI_BLOCK_THEME_STYLE_POPUP);
 
-  const int text_points_max = MAX2(style->widget.points, style->widgetlabel.points);
+  const int text_points_max = std::max(style->widget.points, style->widgetlabel.points);
   int splash_width = text_points_max * 45 * UI_SCALE_FAC;
   CLAMP_MAX(splash_width, CTX_wm_window(C)->sizex * 0.7f);
   int splash_height;